if the first string matches then print the previous line and current line and also print the following lines if the other string search matches.
Input
------
TranTime 2012 10 12
The Record starts here
Accountnumber: 4632473431274
TxnCode 323
TranID 329473242834
ccsdkcnsdncskd wdededadlksadksadaskdsakd
dadscczxczccc
Balance 2000.00
TranTime 2012 10 13
The Record starts here
Accountnumber: 5435478454
TxnCode 312
TranID 5634875438
Balance 4000.00
csdhcsdjcsdcsdcnskjcjsdkjsdj
TranTime 2012 10 15
The Record starts here
Accountnumber: 31231231232
TxnCode 212
sdjhcsdjcbsd csdmcndscndskc
TranID 6546754654
Balance 1000.00
Here is what i have tried so far. but no luck.
awk '{
if ($0 ~ /The Record starts here/)
{
print a;
}
{
a = $0;
}
else
if ($0 ~ /TranID|Balance|Accountnumber/)
{
print;
}
else
{
print "else"
}
}'
Expected output.
TranTime 2012 10 12
The Record starts here
Accountnumber: 4632473431274
TranID 329473242834
Balance 2000.00
TranTime 2012 10 13
The Record starts here
Accountnumber: 5435478454
TranID 5634875438
Balance 4000.00
TranTime 2012 10 15
The Record starts here
Accountnumber: 31231231232
TranID 6546754654
Balance 1000.00
any help will be greatly appreciated.
Thanks.