awk find string and under line print

193 Views Asked by At

I have data that looks like this:

test AA=bddddbs
result=1
cell AA=bnnndb5
result=2
cell1 BB=bnrrndb
result=3

Please help. Find AA=string.

test AA=bddddbs;result=1
cell AA=bnnndb5;result=2

I am use below command and result fail.

nawk '/AA=/{val=$1;next} {print val,$1}' infile
1

There are 1 best solutions below

0
anubhava On

Using awk you can do this:

awk -v OFS=';' '/AA=/{rec=$0; getline; print rec, $0}' file

test AA=bddddbs;result=1
cell AA=bnnndb5;result=2