Adding line with text between pattern and next occurence of the same pattern in bash
Posted
by
kasper
on Stack Overflow
See other posts from Stack Overflow
or by kasper
Published on 2011-02-06T21:15:37Z
Indexed on
2011/02/06
23:25 UTC
Read the original article
Hit count: 316
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.
© Stack Overflow or respective owner