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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Blank Lines Based on First Two Records 2

Status
Not open for further replies.

thunderkid

Technical User
Oct 26, 2000
54
US
I am attempting use awk to add blanks line to records so that I can perform further processing on them. Here is sample of data format:

1.0001 ISR000012 ABFG 1257 IDIE
1.0002 ISR000012 ABAC 4563 DDFF
1.0002 ISR000012 GHFD 5698 RTTT
1.0003 ISR000012 DSAD 4567 KDLS
1.0003 ISR000012 DSAD 4567 KDLS
1.0003 ISR000012 DSAD 4567 KDLS
1.0023 ISR000012 LGKR 8912 OLIS
.
.
.

DESIRED
1.0001 ISR000012 ABFG 1257 IDIE

1.0002 ISR000012 ABAC 4563 DDFF
1.0002 ISR000012 GHFD 5698 RTTT

1.0003 ISR000012 DSAD 4567 KDLS
1.0003 ISR000012 DSAD 4567 KDLS
1.0003 ISR000012 DSAD 4567 KDLS

1.0023 ISR000012 LGKR 8912 OLIS
.
.
.

I want to compare the first two fields and add a blank line after the last record that match. Where there is no match for a record, a single line would be added as shown in the first record in the example.

Thanks for your inputs!

Thunderkid
 
If I understand you correctly, this should do what you want.
Code:
{
  if (f1!=$1 || f2!=$2) {
    if (NR>1) print ""
    f1 = $1
    f2 = $2
  }
  print
}
Hope this helps. CaKiwi
 
Here is further clarification on the thread I entered. I want to compare the first two fields between records. In the sample format I wanted to add line after the first record. A second blank line would come after the thrid record because fields 1 and 2 for record #2 and #3 match and so on. Sorry for any confusion.
Thunderkid
 
Ok, then I think my solution should work. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top