Using `sed` to find and replace in file
sed = Stream EDitor
sed find and replace text
sed 's/word1/word2/g' input.fileFind and replace text and save to new file
sed 's/word1/word2/g' input.file > output.fileNote:
s/means substitute/gmeans global replace
Can change delimiter / to something else:
/ to something else:sed 's~word1~word2~g' input.file > output.fileFind and replace in the line contains something
sed -i -e '/FOO/s/love/sick/' input.txtIn this example only find the word love and replace it with the sick if line content a specific string such as FOO
Find and replace multiple files in sub-folder
find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;-i to save the temporary file
PreviousMacOS's Touch ID on TerminalNextMerging contents of multiple .csv files into single .csv file
Last updated
Was this helpful?