
Hi Friends,
In the record below i have to make changes in the fields by putting the values stored in the temporary variables, x, y, z, p, q, r:
2) In the TBT record store the values in the various fields as:
a) X in a field position 51 to 56
b) Y in a field position 57 to 68
c) Z in a field position 69 to 74
d) P in a field position 75 to 86
e) Q in a field position 87 to 92
f) R in a field postion 93 to 104
TBT0000271422981977 50100001 08071400001100000015011500000100000000772700001200000014238H
Please sujjest me how to make changes through awk if it is possible ...
Thanks
Kanu
If your variables have the exact width:
awk '{print substr($0,1,50)' $x $y $z $p $q $r '}'
Otherwise:
awk '{printf("%s%6s%12s%6s%12s%6s%12s\n") substr($0,1,50)' $x $y $z $p $q $r '}'
Thanks Frank, for giving me info about substr().
But what I want here is to copy the value into the specified field, while your command is printing it on screen.
what about:
awk '{if ( substr($0,12,6)' == "TAB" ####copy 4563 in the above given position######' }' filename
how the command between #### will work?
waiting for your valuable comments
Kanu
I want to change the record:
TAB000025 123338372221004 06000007727RUP 000000080714 862256382 0110HAL OFFICE SkpajiONSHOUSTON TXPCO123456 80021 000000589001055000000030815482
to
TAB000025 567392372221004 06000007727RUP 000000080714 862256382 0110HAL OFFICE SkpajiONSHOUSTON TXPCO123456 80021 000000589001055000000030815482
Any Solutions friends?
Thanks in Advance
Just like the first awk solution you can use the substr function, something like this:
value="567392"
awk '/^TAB/{print substr($0,1,11} '$var' substr($0,18);next}1' file > newfile
There must be spaces around the variable '$var', beware of that.
Regards
This should work:
awk -v v=567392 '/^TAB/{gsub(substr($0,12,6),v,$0)}1' file > new_file