Replace text at multiple files at Linux

To replace txt https://hostname.domain.com/3dpassport at many files at same folder to https://bbbbb.domain.com/3dpassport

sed -i "s/https:\/\/hostname.domain.com/https:\/\/bbbbb.domain.com/g" `grep -l https://hostname.domain.com *`

command explanation:

grep -l will only output the file name.

“ will execute the command and use the result to replace content.

sed -i will directly edit the file.

s/regexp/replacement/

replace the regexp with replacement string.

Leave a Reply