Would like to read the first column then Fill downward Empty Column value with Previous Non-Empty Column value.
Input.txt
20 0 ABC 1 N DEFABC 0 CHARGE
1 ABC 1 N GHIABC 0 CHARGE
2 ABC 1 N JKLABC 0 CHARGE
3 ABC 1 N MNOABC 0 CHARGE
4 ABC 1 N PQRABC 0 CHARGE
210&&-2 0 ABC 1 N DEFABC 0 CHARGE
1 ABC 1 N GHIABC 0 CHARGE
2 ABC 1 N JKLABC 0 CHARGE
3 ABC 1 N MNOABC 0 CHARGE
4 ABC 1 N PQRABC 0 CHARGE
2130&&-4&-6&&-9 0 ABC 1 N DEFABC 0 CHARGE
1 ABC 1 N GHIABC 0 CHARGE
2 ABC 1 N JKLABC 0 CHARGE
3 ABC 1 N MNOABC 0 CHARGE
4 ABC 1 N PQRABC 0 CHARGE
Have tried below command script and it is working fine if the file separted "," de-limiter
and it is not working for FS="" and FS ="" for the above sample input.
$ awk -f FillEmpty.awk Input.txt
$ cat FillEmpty.awk
BEGIN { FS = "" }
$1 != "" { print }
$1 == "" {
# fill in blanks
for (i = 1; i <= NR; i++)
if ($i == "")
$i = Saved[i]
print
}
{
# save all fields
for (i = 1; i <= NR; i++)
Saved[i] = $i
}
Desired Output:
20 0 ABC 1 N DEFABC 0 CHARGE
20 1 ABC 1 N GHIABC 0 CHARGE
20 2 ABC 1 N JKLABC 0 CHARGE
20 3 ABC 1 N MNOABC 0 CHARGE
20 4 ABC 1 N PQRABC 0 CHARGE
210&&-2 0 ABC 1 N DEFABC 0 CHARGE
210&&-2 1 ABC 1 N GHIABC 0 CHARGE
210&&-2 2 ABC 1 N JKLABC 0 CHARGE
210&&-2 3 ABC 1 N MNOABC 0 CHARGE
210&&-2 4 ABC 1 N PQRABC 0 CHARGE
2130&&-4&-6&&-9 0 ABC 1 N DEFABC 0 CHARGE
2130&&-4&-6&&-9 1 ABC 1 N GHIABC 0 CHARGE
2130&&-4&-6&&-9 2 ABC 1 N JKLABC 0 CHARGE
2130&&-4&-6&&-9 3 ABC 1 N MNOABC 0 CHARGE
2130&&-4&-6&&-9 4 ABC 1 N PQRABC 0 CHARGE
Any suggestions ...!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…