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

Nawk/Awk To Select Matching Text & Two Rows Above 1

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a tect file that has text in it below. It has hundreds of lines. I need help only looking for text that matches the characters BOE 602 02/03. If it finds a match it also needs to select the text RXOCF-# about two rows above it and output it to an external file called bad_dxu.txt

It needs to make sure it does not select the text at the top that is similiar to <rxmfp:mo=rxocf-#;

Example input file dxu_start.txt

<rxmfp:mo=rxocf-10;

RADIO X-CEIVER ADMINISTRATION
MANAGED OBJECT FAULT INFORMATION

MO BTSSWVER
RXOCF-10 ERA-G02-R06V0

RU RUREVISION RUSERIALNO
0 BOE 602 02/03 R3D UA10050N1K

RUPOSITION RULOGICALID
C:0 R:L SH: 1 SL: 56 CMRU DXU 0

RU RUREVISION RUSERIALNO
1 BMP903021/1 R7D TU61146085

RUPOSITION RULOGICALID
C:1 R:L SH: 1 SL: 48 DMRU ECU 1

<rxmfp:mo=rxocf-16;

RADIO X-CEIVER ADMINISTRATION
MANAGED OBJECT FAULT INFORMATION

MO BTSSWVER
RXOCF-16 ERA-G02-R06V0

RU RUREVISION RUSERIALNO
0 BOE 602 02/03 R2B/A A53049MXAL

RUPOSITION RULOGICALID
C:0 R:L SH: 1 SL: 56 CMRU DXU 0

RU RUREVISION RUSERIALNO
1 BMP903021/1 R7D A083393605

RUPOSITION RULOGICALID
C:1 R:L SH: 1 SL: 48 DMRU ECU 1

<rxmfp:mo=rxocf-88;

RADIO X-CEIVER ADMINISTRATION
MANAGED OBJECT FAULT INFORMATION

MO BTSSWVER
RXOCF-88 ERA-G02-R06V0

RU RUREVISION RUSERIALNO
0 BOE 602 11/11 R1F A101684004

RUPOSITION RULOGICALID
C:0 R:L SH: 1 SL: 56 CMRU DXU 0

RU RUREVISION RUSERIALNO
1 BMP903021/1 R7C A082561339

RUPOSITION RULOGICALID
C:1 R:L SH: 1 SL: 48 DMRU ECU 1

--------------------------
Output to file: bad_dxu.txt

RXOCF-10 BOE 602 02/03 R3D
RXOCF-16 BOE 602 02/03 R2B/A
 
Something like this ?
awk '
/^RXOCF-[0-9]/{rxocf=$1;next}
/BOE 602 02\/03/{print rxocf "BOE 602 02/03 " $5}
' dxu_start.txt > bad_dxu.txt

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I try to run it like above but I get back the following error.

bhmws13{root} #: nawk -f dxu_awk dxu_start.txt
nawk: syntax error at source line 1
context is
nawk >>> ' <<<
nawk: bailing out at source line 1
 
The contents of dxu_awk should be this:
/^RXOCF-[0-9]/{rxocf=$1;next}
/BOE 602 02\/03/{print rxocf "BOE 602 02/03 " $5}

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you it worked out great! Saved 10 hours.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top