开发者

find and replace from command line unix

I have a multi line text file where each line has the format

..... Game #29832: ......

I want to append the character '1' to each number on each line (which is 开发者_开发百科different on every line), does anyone know of a way to do this from the command line?

Thanks


sed -i -e 's/Game #[0-9]*/&1/' file

-i is for in-place editing, and & means whatever matched from the pattern. If you don't want to overwrite the file, omit the -i flag.


Using sed:

cat file | sed -e 's/\(Game #[0-9]*\)/\11/'


sed 's/ Game #\([0-9]*\):/ Game #1\1:/' yourfile.txt


GNU awk

awk '{b=gensub(/(Game #[0-9]+)/ ,"\\11","g",$0); print b }' file
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜