Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clean text

Status
Not open for further replies.

darioit

IS-IT--Management
Sep 23, 2010
3
0
0
IT
Hello,
I take a list of zip file using command "7za.exe l file.zip", so I want use gawk to clean output

Ho can I clean this result:
2016-04-09 13:16:45 ....A 105907 123412 abc_def_c_hil.pdf
2016-04-09 13:16:45 ....A 105907 aa_bb_cc_dd.pdf
2016-04-09 13:16:45 ....A 105907 directory\ee_ff_gg_hh.pdf

to have this:
abc_def_c_hil.pdf
aa_bb_cc_dd.pdf
ee_ff_gg_hh.pdf

thank you in advance

 
I you have the result in a file, e.g.
Code:
$ cat darioit.txt
2016-04-09 13:16:45 ....A 105907 123412 abc_def_c_hil.pdf
2016-04-09 13:16:45 ....A 105907 aa_bb_cc_dd.pdf
2016-04-09 13:16:45 ....A 105907 directory\ee_ff_gg_hh.pdf
then you can clean the output like this
Code:
$ cat darioit.txt | awk '{str=$NF; sub(/.*\\/,"", str); print str}'
abc_def_c_hil.pdf
aa_bb_cc_dd.pdf
ee_ff_gg_hh.pdf

 
since the output is always in column 5 as delimited by space, you can print $5

awk -F" " '{print $5}' /path/to/file

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
My bad!
Since the output is always in the last column, you can print $NF

awk -F" " '{print $NF}' /path/to/file

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
johnherman said:
the output is always in the last column, you can print $NF
and if necessary you have to remove the directory name too - see my previous post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top