开发者

sed character replacement in portion of a line

开发者 https://www.devze.com 2022-12-29 06:52 出处:网络
New to sed and could use some help. I would like to turn this \"a/b/ca/b/c\" 开发者_开发知识库into this \"a/b/ca-b-c\".

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

精彩评论

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

关注公众号