---------- Post updated at 03:41 PM ---------- Previous update was at 01:46 PM ----------
I need one more help.
I have another file(fixed length) that will get negative value (ex:-00000000003000) in postion (98 - 112) then i have to convert the value to 000000000000000(15 zeros-length is 15) and then print the entire record.
I have used substr($0,98,15) function and getting syntax error.
You are one infraction away from being set read-only. Please start using code tags.
awk doesn't work like that, it's for delimited files, not fixed-width ones. You can assign text to column numbers, but you can't assign it to the return of a function.
If you have GNU awk, you could do awk -v FIELDWIDTHS="width1 width2 width3 ..." '$5 ~ /-/ { $5="000000" } 1' inputfile outputfile , with 'width1' etc replaced by the widths of your columns, and 5 replaced by your column number... FIELDWIDTHS is a special variable GNU awk uses to deal with fixed width files.