Just noting a few sed tricks that I’ve been using while working with large sql scripts and some search and replace tricks that are made so much easier on the command line.
Insert text at the beginning of a file:
sed -i '1i\
content to insert at the beginning' file_to_work_on.txt
-i specifies to edit in place as opposed to writing the result to stdout. 1i seems to specify to insert at line 1, and the slash forces a line break which seems to be part of the syntax Insert a line with i
and to append a line to the end of a file
sed -i '$a\
Append this after the final line' file_to_work_on.txt
basically the same syntax.
You can group multiple actions together with braces
sed -i '1{
i\
Insert this before the first line
a\
Add this after the first line
c\
Change the first line to this
}' file_to_work_on.txt
Really useful and often faster than loading a file up in an editor especially when edits need to be made across a group of similar files or really large text files.