I want to modify the field 5 and field 4 as below.
If value in field 5 is null then value of field 4 should be in field 5 . and then the value of field 4 should change to field 2 - field 5 .
I agree with your comments. Here i am posting the original Input. In this input i am looking for 25th col and 24th col. I have tried the code on this as well. But not getting the results.
The output values are same as Input but with one extra column at the end containing zeros.
I can't replicate the behaviour you describe. In your new input sample, $24 is NOT empty in any line. $24 already HAS the difference between $2 and $25. And, as said before, with multiple spaces as field separators, you can't detect empty fields.
---------- Post updated at 02:23 AM ---------- Previous update was at 02:18 AM ----------
The problem is each field in my Input data is containing 7 columns. Some fields are having values in all the 7 cols and some fields are having blanks in 7 cols(null).
Anyways thanks for your time on this Rudi.
I will try to do this in some other platform then.
Thanks & Regards,
am24
---------- Post updated at 02:30 AM ---------- Previous update was at 02:23 AM ----------
Hi Looney.
Thanks for the code. I have applied it but not achieved the results .
Looks like we've been talking past each other; the definition of <TAB> as the input and output field sepatator is responsible for the 0 field at EOL. For fixed widths fields this obviously doesn't work... a clear specification as the first step would have helped?
GNU awk has the FIELDWIDTHS variable which could help in your case of constant field widths. For NON-GNU awk , try
awk '
{CNF = (length()-4)/8 # as NF doesn't count fields correctly, create a "corrected" NF from line length
printf "%3s", substr ($0, 1, 3) # the first field can be printed independently, and must be as it deviates in format
for (i=0; i<=CNF; i++) T[i+2] = substr ($0, 4+i*8, 8) # fill in the T array with respective fields 8 chars long.
T[25] = (T[25]+0)?T[25]:T[24] # do the requested field shifting
T[24] = T[2] - T[25] # do the requested arithmetics
for (i=2; i<=CNF+2; i++) printf "%8s", T # formatted print of the residual fields
printf RS # print line feed
}
' file