sed is a multi purpose tool that can be used for many endpoints. The way sed will be used in this matter is by replacing different words and characters, and finally pushing them to another file, or a file itself.
# syntaxsed<QUERY><FILE>##### make a test file with the contents of /etc/passwdcat/etc/passwd>test.txt##### examples 1sed 's/root/ROOT/g' test.txt # changes all the words in the file test.txt that match root to ROOT (only in the terminal, not in the file)
sed 's/root/ROOT/1' test.txt # changes the first match (root) in the file test.txt that matches root to ROOT (only in the terminal, not in the file)
sed 's/root/ROOT/2' test.txt # changes the second match (root) in the file test.txt that matches root to ROOT (only in the terminal, not in the file)
##### examples 2cat test.txt | sed 's/root/ROOT/g' # changes all the words in the file test.txt that match root to ROOT (only in the terminal, not in the file)
cat test.txt | sed 's/root/ROOT/1' # changes the first match (root) in the file test.txt that matches root to ROOT (only in the terminal, not in the file)
cat test.txt | sed 's/root/ROOT/2' # changes the second match (root) in the file test.txt that matches root to ROOT (only in the terminal, not in the file)
##### make changes on a specific linesed'3 s/usr/USR/g'test.txt# makes the change only on line 3 of the file##### make changes on multiple specific linessed'2,4 s/usr/USR/g'test.txt# makes the change on line 2, 3 and 4.##### Submit the changes to the filesed-i's/root/ROOT/g'test.txt# successsed-i's/root/ROOT/1'test.txt# successsed-i's/root/ROOT/2'test.txt# successcattest.txt|sed-i's/root/ROOT/g'# failurecattest.txt|sed-i's/root/ROOT/1'# failurecattest.txt|sed-i's/root/ROOT/2'# failuresed--help# get help from the toolsed--version# get the current version of the tool