Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux find and replace

Tags:

linux

shell

How can I replace "abc" with "abcd" on all files of a folder using shell?

Is it possible using sed command?

like image 820
Subhojit Mukherjee Avatar asked Dec 21 '11 11:12

Subhojit Mukherjee


2 Answers

Try the following command for the file file.txt:

sed -i 's/abc/abcd/g' file.txt


Try the following command for all files in the current folder:

find . -maxdepth 1 -type f -exec sed -i 's/abc/abcd/g' {} \;

For the files in the current directory and all subdirectories:

find . -type f -exec sed -i 's/abc/abcd/g' {} \;

Or if you are fan of xargs:

find . -type f  | xargs -I {}  sed -i 's/abc/abcd/g' {}
like image 54
kbdjockey Avatar answered Oct 08 '22 16:10

kbdjockey


sed -i 's/abc/&d/g' *

should work.

like image 45
Nikodemus RIP Avatar answered Oct 08 '22 17:10

Nikodemus RIP