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
精彩评论