开发者

sed character replacement in portion of a line

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


Give this a try:

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


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

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


you can use awk,

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


This might work:

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

Or this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜