Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Tough nut to crack) AWK, copy matching 2 col & 10-12 rows, is it possible?

Status
Not open for further replies.

awkawed

Technical User
Jun 1, 2015
1
CA
Hey guys, my first post here.
I'm trying to use awk to copy all matching paragraphs from one file

The file looks like this :

Test Case Number 990990003099
Card Type CCCC
Transaction Type Sale
Entry Mode Keyed
Account Number 4099562299219923
Transaction Amount 78.88
Description lorem ipsum lorem ipsum
AVS Billing Postal Code 99999
Response Code 999
AVS Result Code A
Test Case Number 000990003099
Card Type CCCC
Transaction Type Sale
Entry Mode Keyed
Account Number 4909969931992993
Transaction Amount 78.90
Description lorem ipsum lorem ipsum
AVS Billing Postal Code 99999
Response Code 999
AVS Result Code Z

I need to copy from the line that says "Test Case" to another "Test case" if the "Transaction Type" equals a certain word, ether, "Sale", "Refund" or other type that I set.

The data set is spread across 2 columns and 10-12 rows.

Is it possible to copy with awk? If yes, then ... how?

Thank you, your help is greatly appreciated.
 
. . . e t c
Is it possible to copy with awk? If yes, then ... how?
First you need to explain (clarify) what you mean by "...copy from the line that says "Test Case" to another "Test case"
Post an example of the results you expect.
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
If your source file is named "test.txt", you could try something like this:
Code:
awk '
$0 ~ "Test Case Number" {t=$NF}
$0 ~ "Transaction Type" {if($NF=="Sale"||$NF=="Refund"){print t": "$NF}}
' test.txt
[noevil]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top