sed insert multiple lines before multiple lines pattern -
i have following long file:
... close unit 1 ... ... close unit 1 ... ... close unit 1 stop i want insert multiples lines before last close unit 1 before stop. file contains undefined number of close unit 1.
i found lot of other similar questions here , there, answers couldn't me... example tried https://stackoverflow.com/a/8635732/1689664 didn't work...
using sed , tac:
$ tac inputfile | sed '/close unit 1/ {s/\(.*\)/\1\nline3\nline2\nline1/; :loop; n; b loop}' | tac ... close unit 1 ... ... close unit 1 ... ... line1 line2 line3 close unit 1 stop note you'd need specify input lines in reverse order in sed expression.
Comments
Post a Comment