I need to replace a column value in a fixed width file which is having unknown value in one of the columns and need to replace the column value with some column value in the same line.
A B C D E F G H I J K L M N
ex: 123908 456567 675674 0000000x 45678 09756 125678 45678 09756 125678 45678 09756 125678 45678 09756
here instead of 0000000x
(column D), I need to replace it with 125678
(column G).
I have tried:
awk 'BEGIN{FS=OFS=""}{f=0;for(i=292;i<=300;i++){if($i!~/0000000X/){f=1}};if(f) {for(i=292;i<=300;i++){$i=2}};print }'
This command is changing for the respective column in all rows. But I need to be changed for the particular column having the 0000000x
value.
for
loop)? You don't use the G column in your one liner. How do you determine theG
column?0000000x
because it has that value in column D or do you need to change whatever value is in column D? SettingFS=""
is undefined behavior so it'll do different things in different awks but none of them will do anything you want to do. You say your input is fixed width fields but then you show input that has space-separated fields and you don't tell us the start char pos and length of "column D" or "column G" if the input really is fixed width so it's hard to know how to help you.