Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
Consider a sample test file (test.txt) with these contents
This is a sample program.
abc def ghi klm abc opq abc
Now let us use sed
sed -i 's/abc/ABC/' test.txt
cat test.txt
The above example shows that the sed command has replaced the first occurrence of ‘abc’ with ‘ABC’.
This is a sample program.
ABC def ghi klm abc opq abc
If we want to replace all occurrences of ‘abc’ by ‘ABC’, then the following command will do the work for us
sed -i 's/abc/ABC/g' test.txt
cat test.txt
It is important to note here that ‘sed -i’ overwrites the original file with the new one.
Add Comment
Please, Sign In to add comment