Replacing a gray character in a part of a line

New to sed and may use some help. I would like to include this "a / b / ca / ​​b / c" in this "a / b / c abc". where a / b / c is any path.

thanks

+2


a source to share


4 answers


Try:



sed 'h; s/ .*//; x; s/.* //; s:/:-:g; x; G; s/\n/ /'

      

+1


a source


Since you want to use spaces for deletion, I would just use perl:



perl -ane '$F[1] =~ s/\//-/; print "@F\n"'

      

0


a source


you can use awk,

$ echo "a/b/c a/b/c" | awk '{gsub("/","-",$NF)}1'
a/b/c a-b-c

      

0


a source


This might work:

echo "a/b/c a/b/c" | sed ':a;s|\(.* [^/]*\)/|\1-|;ta'
a/b/c a-b-c

      

Or that:

echo "a/b/c a/b/c" | sed 's/.* //;h;y/\//-/;x;G;y/\n/ /'
a/b/c a-b-c

      

0


a source







All Articles