The basic idea n using sed (Stream EDitor)is to read lines one at a time from the input files, apply commands from the list (placed within single quotes), in order, to each line and write the edited output to the standard output. The syntax looks like the following:
sed 'list of ed commands' filenames
Below we will provide a series of useful usages.
sed 's/Alice/Amber/g' TicTacToe.java > output
However the above does not change the file. We have to save the output and rename it to the actual file name, as shown below. Make sure to check the output to verify that the changes have occurred correctly before renaming it!
mv output > TicTacToe.java
sed 's/^/\t/' file1
where \t represents the tab character. We can then just pipe the output to lpr to send it to the printer.
sed 's/^/\t/' file1 | lpr
cat file2 | sed 3q
sed -n '/pattern/p'
does the same job as grep.
sed 's/$/\n/'
sed -n '20,30p' print lines 20 through 30 sed '1,10d' delete lines 1 through 10 sed '1,/^$/d' delete up to and including the first blank line sed '$d' delete last line