sed + match directory PATH from line by sed
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 lin开发者_JAVA百科e
for example
echo "PATH: word1 /var/tmp word2 word3" | sed ...
will print
/var/tmp
$ 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.
echo 'PATH: word1 /var/tmp word2 word3' | cut -d ' ' -f 3
精彩评论