Q . How to Find and Replace text of any file using command line in linux.
@mit $ingh. asked, May 31 ' 2017I have a file named test.txt.
I want to replace all abc text to xyz using command line in ubuntu.
1 Answers
sed -i 's/original/new/g' file.txt
Explanation:
sed
= Stream EDitor-i
= in-place (i.e. save back to the original file)The command string:
s
= the substitute commandoriginal
= a regular expression describing the word to replace (or just the word itself)new
= the text to replace it withg
= global (i.e. replace all and not just the first occurrence)
file.txt
= the file name