Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find and replace from command line unix

Tags:

replace

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

like image 591
Aly Avatar asked Feb 23 '10 17:02

Aly


2 Answers

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.

like image 106
Alok Singhal Avatar answered Nov 15 '22 07:11

Alok Singhal


Using sed:

cat file | sed -e 's/\(Game #[0-9]*\)/\11/'
like image 42
anshul Avatar answered Nov 15 '22 09:11

anshul