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!

Grep and Awk Question

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a file which has text like below in it:

A2/APT "BH2BSC2 D000000" 647 020613 0819
DIGITAL PATH FAULT SUPERVISION

DIP DIPEND FAULT SECTION HG DATE TIME
58RBLT ALL1 020613 081920

I want to search or grep for DIGITAL PATH FAULT SUPERVISION in the file and then redirect the output to another file called beaster1 so I only end up with:

58RBLT ALL1

Basically I want to look for the DIGITAL PATH FAULT SUPERVISION words, then only redirect the words under DIP and FAULT to a new file like above......

Thanks a bunch!
Beaster.//

 
Hi Beaster,

This seems to work with the data you gave and should get you started for more general data.
Code:
{
  if ($0 == "DIGITAL PATH FAULT SUPERVISION") {
    flg = 1
  }
  else if (flg == 1 && $1 == "DIP"){
    flg = 2
    k = index($0,"FAULT")
  }
  else if (flg == 2) {
    print $1 " " substr($0,k,6)
    flg = 0
  }
}
Hope this helps. CaKiwi
 
That looks great,
I have it working since this post using :

fgrep -f dip_faults nv1bsc1_stripped1 > beaster1

awk '
{
printf("%s %s\n", $1, $2)
} ' < beaster1 >> nv1bsc1_stripped2

rm beaster1

I will know in ten minutes if it succeeds well enough to use....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top