LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to get the pattern using sed or awk? (https://www.linuxquestions.org/questions/programming-9/how-to-get-the-pattern-using-sed-or-awk-574134/)

ahpin 08-02-2007 02:58 AM

How to get the pattern using sed or awk?
 
I would like to know how can i used the sed or awk to help me captured out the user name only from the file pattern as below:

/nfs/disk001/jeff
/nfs/disk002/mery
/nfs/homedisk01/kathie
/nfs/localhome/joseph
/nfs/disk02/catherine


The end result will be:
jeff
mery
kathie
joseph
catherine

Thanks.

colucix 08-02-2007 03:08 AM

Have you any experience in awk? Here you can define a field separator other than the blank space(s) and get the last field of each line, as in
Code:

gawk -F\/ '{print $NF}' dirlist
where dirlist is a file containing your input lines. Or in alternative you can simply pipe the input from another command to gawk.

jschiwal 08-02-2007 03:13 AM

sed 's#^.*/##' file

or

for line in $(cat testfile); do basename $line; done

ahpin 08-02-2007 03:16 AM

Brilliant!!!
Thanks for all your help....it is working now...real great.....


All times are GMT -5. The time now is 05:06 PM.