tags:

views:

41

answers:

3

New to sed and could use some help. I would like to turn this "a/b/c a/b/c" into this "a/b/c a-b-c". where a/b/c is any path.

thanks

A: 

Since you want to use whitespace to delemit, I'd just use perl:

perl -ane '$F[1] =~ s/\//-/; print "@F\n"'
Jefromi
Thanks for your replyafter a space defines the second part of the lineI tried your first suggestion, but it did not work for meecho "a/b/c a/b/c"|sed 's@\( .*\)-@\1/@g'a/b/c a/b/c
BobBobBob
Sorry, not sure what happened when I pasted in the first pattern; it's obviously completely wrong. But the perl one's way more robust if you want to use whitespace to delimit.
Jefromi
A: 

Give this a try:

sed 'h; s/ .*//; x; s/.* //; s:/:-:g; x; G; s/\n/ /'
Dennis Williamson
Perfect, thanks much!
BobBobBob
@BobBobBob: I'm glad you found it acceptable. ;-)
Dennis Williamson
A: 

you can use awk,

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