cjmling / findings

Notes on stuff i finds worth keeping for quick reference later on.
2 stars 0 forks source link

Linux find and replace text #147

Open cjmling opened 5 years ago

cjmling commented 5 years ago

sed -i 's/old-text/new-text/g' input.txt

It tells sed to find all occurrences of ‘old-text’ and replace with ‘new-text’ in a file named input.txt

https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/

cjmling commented 5 years ago

In case search and replace have / character then we can change the deliminator.

example :

Find word http:// and replace with https://www.cyberciti.biz:

sed 's/http:///https://www.cyberciti.biz/g' input.txt (this will throw error)

can be written as

sed 's+http://+https://www.cyberciti.biz+g' input.txt