Adding line with text between pattern and next occurence of the same pattern in bash
- by kasper
I am writing a bash script that modifies a file that looks like this:
--- usr1 ---
data data data data
data data data data
data data data data
--- usr2 ---
data data data data
data data data data
--- usr3 ---
data data data data
--- endline ---
One question is: How to add next user line --- usrn --- after last user data lines?
Second one is: How to delete specific user data lines (data lines and --- userx ---) i.e. I would like to delete usr2 with all his data set.
It must work on bash 2.05 :) and I think it will use awk or sed, but I'm not sure.