Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

sed print first line before regexp and all lines after

$
0
0
Hi All

I'm trying to extract the line just above a regexp and all lines after this.

I'm currently doing this in two steps

Code:

sed -n -e "/^+---/{g;p;}" -e h oldfile.txt > modified.txt
sed -e "1,/^+---/d" -e "/^$/d" oldfile.txt >>modified.txt

Sample
Code:

sometext will be here
sometext will be here
sometext will be here
sometext will be here



 ACD                  (A)                 
+------------------------+------------------------
 (some info)                        19082
 (something else)                        19082

Result
Code:

ACD                  (A)                 
 (some info)                        19082
 (something else)                        19082

Is there a way I can achieve this using a one liner?

Viewing all articles
Browse latest Browse all 16232

Trending Articles