开发者

find and replace from command line unix

开发者 https://www.devze.com 2022-12-21 13:09 出处:网络
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

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

精彩评论

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