Printing the lines which proceeds the particular string

Hi,

We are facing some issues while finding the particular string.
Our file is:

 cat 1.txt
Node Name(s) [node01]
Preparation fragment

Partition: [Partition #1]
Transformation instance: [SQ_LOANS]
Transformation: [SQ_LOANS]
Applied rows: [101]
Affected rows: [101]
Rejected rows: [0]
Throughput(Rows/Sec): [104]
Throughput(Bytes/Sec): [0]
Last error code [0], message [No errors encountered.]


Partition: [Partition #1]
Transformation instance: [LOANS]
Transformation: [LOANS]
Applied rows: [15]
Affected rows: [15]
Rejected rows: [0]
Throughput(Rows/Sec): [987]
Throughput(Bytes/Sec): [0]
Last error code [0], message [No errors encountered.]

Now we just want "Applied rows" which belongs to only LOANS.
That is the output will be:

Transformation: [LOANS]
Applied rows: [15]

How can we grep only LOANS (not SQ_LOANS) from the file along with its Applied rows??

I have tried to create new file which will be having line number.Following are the commands which i tried:

cat -n 1.txt > 1_new.txt
val=`cat 1_new.txt | fgrep -w "LOANS' | fgrep -w "Transformation instance"`
new_val=`expr $val + 2`
cat 1_new.txt| grep $new_val

Any idea to achive this ?? :confused: :confused:

Thanks in Advance!!

awk '/Transformation:/ && $2=="[LOANS]" {getline; print}' file
$ awk '/Transformation: \[LOANS\]/,/Applied rows/' 1.txt
Transformation: [LOANS]
Applied rows: [15]

Hey!! thanks for the reply :smiley: :smiley:

Now its working fine... with just one command :smiley: