×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Clean text

Clean text

Clean text

(OP)
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

RE: Clean text

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 

RE: Clean text

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


RE: Clean text

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


RE: Clean text

Quote (johnherman)


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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close