I want to find and replace a value inside awk block.
Here is a sample input file to my script
P1
10,9:11/18013013582
,10:1
,167:0
,487:5/E.164
11,9:15/310410532169026
,10:60
,167:0
,487:4/IMSI
12,18:15/013329002130500
,19:0
15,9:10/9609610015
,10:1
,14:68
,167:0
,436:5/ABCDE
,487:5/E.164
16,87:1
17,9:10/8013765024
,10:1
,11:1
,12:0
,167:0
,487:5/E.164
23,9:11/13123149810
,10:1
,11:1
,167:0
,487:5/E.164
P3
42,3:1.
,4:3
,300:1.
43,3:1.
,4:3
,300:1.
44,3:0.
,4:7
,300:0.
45,5:0.3
And here is the piece of code that I am currently using,
nawk -v fname="${filename}" -F '/|:' '
function isnum(x){return(x==x+0)}
/P1/,/P3/{
# Found start increment i reset variables go to next line
if(/P1/){
++i
fid =""
count++
next
}
# Found end validate variable and print go to next line
if(/P3/){
printf "%s|",count
printf "%s|",isnum(fid)?fid:"NULL"
next
}
if(!fid && /36,59:*/)
{
fid = $NF
}
' ${filename} >>output.txt
Basically, I my input file will contain several P1/P3 blocks, I am taking one block at a time and finding out value from it. Now, what I want to basically do is change the value of first ,11:1 (i.e the one after 17,9 part) into 11:2 based on the value of 17,9:10/8013765024.
Please note there can be several ,11 before and after but those have to remain unchanged.
Please suggest how to proceed further. I am very new to both awk and sed.
Also, I tried writing a regular expression but could not figure out it properly. Here it is,
17[,0-9:\]*[\n]*,11
17,9:10/8013765024/^17[,0-9\:]*$/ { found=1 } found&/^,11/ { do things; found=0 }