Search code examples
perlperl-moduleperl-data-structures

How to remove some entries in a file?


-rw-r--r-- 1 root root 3178 Jun 29 16:08 FTS_TESTCAMPAIGN1_29_06_2013_160823.html
-rw-r--r-- 1 root root  711 Jun 29 16:08 FTS_ABORT_BACKUP_JOB_1_29_06_2013_160823.html
-rw-r--r-- 1 root root  405 Jun 29 16:08 FTS_ABORT_BACKUP_JOB_1_29_06_2013_160823.csv
-rw-r--r-- 1 root root  466 Jun 29 16:08 FTS_ABORT_BACKUP_JOB_1_29_06_2013_160823
-rw-r--r-- 1 root root 3178 Jun 29 16:14 FTS_TESTCAMPAIGN1_29_06_2013_161404.html
-rw-r--r-- 1 root root  711 Jun 29 16:14 FTS_ABORT_BACKUP_JOB_1_29_06_2013_161404.html
-rw-r--r-- 1 root root  405 Jun 29 16:14 FTS_ABORT_BACKUP_JOB_1_29_06_2013_161404.csv
-rw-r--r-- 1 root root  466 Jun 29 16:14 FTS_ABORT_BACKUP_JOB_1_29_06_2013_161404
-rw-r--r-- 1 root root    0 Jun 29 16:25 log

I have the directory lising in a file as above. I need the output as:

FTS_TESTCAMPAIGN1_29_06_2013_160823.html
FTS_ABORT_BACKUP_JOB_1_29_06_2013_160823.html
FTS_ABORT_BACKUP_JOB_1_29_06_2013_160823.csv
FTS_ABORT_BACKUP_JOB_1_29_06_2013_160823
FTS_TESTCAMPAIGN1_29_06_2013_161404.html
FTS_ABORT_BACKUP_JOB_1_29_06_2013_161404.html
FTS_ABORT_BACKUP_JOB_1_29_06_2013_161404.csv
FTS_ABORT_BACKUP_JOB_1_29_06_2013_161404
log

How can I do it using Perl?


Solution

  • As long as the directory listing maintains the same structure, the following quick and dirty perl one-liner will do the job:

    perl -pi.bak -ae 's/^.*$/$F[8]/' FILENAME