I have a script that matches two fields (at position 7 length 20 and position 479 length 6) and inserts character '01' and '02' on subsequent matching records. Works fine so far.
Now, I want to replace (say position 6) with 'Y' in the first record of the matching condition.
ie. When I get to the '02' matching result, I want to replace position 6 with 'Y' of the previous line that matched '01'
How do I do this?
-KAT
awk '{
curr1 = substr($0, 7, 20);
curr2 = substr($0, 479, 6);
if (curr1 == last1 && curr2 == last2)
{
printf("02%s\n", $0)
}
else
{
printf("01%s\n", $0)
last1 = curr1
last2 = curr2
}
}'
Now, I want to replace (say position 6) with 'Y' in the first record of the matching condition.
ie. When I get to the '02' matching result, I want to replace position 6 with 'Y' of the previous line that matched '01'
How do I do this?
-KAT
awk '{
curr1 = substr($0, 7, 20);
curr2 = substr($0, 479, 6);
if (curr1 == last1 && curr2 == last2)
{
printf("02%s\n", $0)
}
else
{
printf("01%s\n", $0)
last1 = curr1
last2 = curr2
}
}'