tags:

views:

16

answers:

2

hi have in file the example line: (in file)

PATH: word1 /var/tmp word2 word3

how to rescue or match only "/var/tmp" PATH from the line by sed

remark: /var/tmp its only example , it could be any other path!

remark1: /var/tmp could be in the first line or in the end of the line or somewhere in the middle of line

for example

 echo "PATH: word1 /var/tmp word2 word3" | sed ...

will print

/var/tmp
A: 
$ cat file
PATH: word1 /var/tmp word2 word3
$ awk '{for(i=1;i<=NF;i++)if($i ~/\//) print $i}' file
/var/tmp

This does not work if you have directory names with spaces. Provide a more concrete example of the possible paths that you might have. best of all, tackle the root of the problem at the source, where you got your data from.

ghostdog74
A: 

echo 'PATH: word1 /var/tmp word2 word3' | cut -d ' ' -f 3

ssegvic
The OP said that the path is not always in the same spot within a line.
B Johnson
That's not a problem, it appears you haven't tested my solution. The cut simply selects the third space-delimited field. The only situation in which this would not work is when there are spaces in the path.
ssegvic