For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2004 > extract a specific substring









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author extract a specific substring
Marco Meoni

2004-05-21, 6:30 pm

Hi to all,
I'm an awk newbie.

I have a text file like this:

aaa /home/smith/subfolder1/filename1.ext1 bbb
ccc /home/smith/subfolder1/subfolder2/filename2.ext2 ddd
eee /home/smith/subfolder1/filename3.ext3 fff
::::

I should extract (for further parsing) the filenames above: in other words
the substrings between the LAST slash '/' (excluded) and the last space ' '
(excluded)

filename1.ext1
filename2.ext2
filename3.ext3
:::::

thanks a lot

Marco


Ed Morton

2004-05-21, 6:30 pm



Marco Meoni wrote:

> Hi to all,
> I'm an awk newbie.
>
> I have a text file like this:
>
> aaa /home/smith/subfolder1/filename1.ext1 bbb
> ccc /home/smith/subfolder1/subfolder2/filename2.ext2 ddd
> eee /home/smith/subfolder1/filename3.ext3 fff
> ::::
>
> I should extract (for further parsing) the filenames above: in other words
> the substrings between the LAST slash '/' (excluded) and the last space ' '
> (excluded)
>
> filename1.ext1
> filename2.ext2
> filename3.ext3
> :::::
>
> thanks a lot
>
> Marco
>


awk -F '[ /]' '{print $(NF-1)}'

Regards,

Ed.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com