sed 10q demo.txt
- prints first 10 lines
sed -i'.bak' 's/hello/bar/' demo.txt
- replace the first "hello" on each line with "bar"
sed -i'.bak' 's/hello/bar/g' demo.txt
- replace the ALL "hello" on each line with "bar"
sed -i'.bak' '3d' demo.txt
- remove the 3rd line in a file
sed -i '' -e "2s/^//p; 2s/^.*/var exports = {};/" demo.txt
- insert a new line on the 3rd row. (duplicate 2nd and edit the copy) (do it inplace)
sed -i '' '3i\'$'\n''var exports = {};' demo.txt
- insert at the beginning of the 3rd line (do it inplace)