If you have exported your spreadsheet to file1.csv
, as shown, do
#!/bin/sh awk -F, -v OFS=, ' NR==1 { for (i = 1; i <= NF; i++) { if ($i == "") $i = prev prev=$i } } { print }' < file1.csv > file2.csv
-F, -v OFS=,
setsawk
’s input and output file separators to,
.NR==1
means “do the following on the first record (line/row) only”.- The
for
loop looks at each field (cell) in the first row, and, if it’s blank, sets it equal to the preceding value. { print }
prints all records fromfile1.csv
tofile2.csv
, with the first one being modified (as described above) and all others being passed through from input to output (so empty cells below the first row won’t be tampered with).