Find and replace from the unix command line

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

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

I want to add the character “1” to each number on each line (which is different on each line), does anyone know how to do this from the command line?

thank

+5
source share
4 answers

Usage sed:

cat file | sed -e 's/\(Game #[0-9]*\)/\11/'
+4
source
sed -i -e 's/Game #[0-9]*/&1/' file

-iDesigned for in-place editing, which &means everything that matches the template. If you do not want to overwrite the file, omit the flag -i.

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

GNU awk

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

All Articles