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

Find A pattern and then sub 1

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

I have a file that looks like this
<AT 1.1 LV 1.1 NT 3.4.0.0 >O
b
J
2 Q
3 CDR b
J
101 C
S7 A
1 O D
1 D
0 D
0 D
0 D
0 D
0 D
0 D
0 D
128 A <------------- Pattern
9 514058912 A <-- must sub to "10 0514058912"
9 51405EEEE D <-- must sub to "10 051405EEEE"
0 D
0 D
0 A
0 M
1078569424 0 D
2004 D
3 D
6 D
12 D
37 D
4 D
0 D
7 A
Ap

First find pattern "128 A" then next if ($(e+1)==9){sub{9,10,$1};{sub(514058912,0514058912,$2} untill the end. Please note that 514058912 can start with any number eg 12345677 or 34555555.

Many Thanks
Chris
 
Something like this ?
awk '
/^128 A/{++a}
/^9 /{if(a){$1="10";$2="0"$2}
1' /path/to/input >output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PH,

Thanks, it works. Had to make some changes like
awk '
/^128 A/{++a}
/^9 [0-9]/{if(a){$1="10";$2="0"$2}}1'

By the way whats the meaning on the "1" at the end.

Thanks Once Again.
Chris
 
The 1 is a shorthand for {print}.
1 always evaluate to true and the default action is print.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top