INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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.

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

Quote:

. . . 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

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close