sed - linux

Delete block of text that matches first line

sed -i '/Some arbitrary text to match/,/^$/d' filename
# -i ticker deletes lines from file in place
        

Append hyphens using sed

# Probably better to just echo lines in
echo "your 1st line\nyour 2nd line" >> file
        

Remove grouped new lines and consolidate them to one new line

sed '/^$/N;/^\n$/D' inputfile

# Admittedly I don't understand how this works but it does, and currently not motivated to look it up
        

Recursively replace matching string

grep -rli 'old-word' * | xargs -i@ sed -i 's/old-word/new-word/g' @
        

Insert line after specific line

sed -i '<line number> a <what you want to write>' filename
        

Insert line after matching line (or before)

# after match
sed -e '/regex_match/a\' -e 'replacement_text' file

# before match
sed -e '/regex_match/i\' -e 'replacement_text' file