Useful things (for me, at some point) that can be done in one line using shell script
- Comment out all lines of a text file and writes the command output in a new text file;
sed -E '/^[[:space:]]*(#|$)/! s/^/#/' [file] >> [newfile]
- Do the same thing as the previous command, however, overwrites the original file with the changes. Use this form very carefully!
sed -iE '/^[[:space:]]*(#|$)/! s/^/#/' [file]
- The following command allows define a line range to comment out and sends the output to a new text file.
sed -nE -e 'startline,endline p' [file] | sed -E '/^[[:space:]]*(#|$)/! s/^/#/' >> [newfile]