How to append to the lines with fewer columns in a tab separated text file?
问题 I have a tab separated text file. Some rows have 10 columns and some rows have 11 columns. I want to add an extra column to the last of 10 column rows with the value 0. How can i do this? 回答1: Since you have mentioned append, you can awk as below awk -F $'\t' 'BEGIN {OFS = FS} NF==10{$0=$0"0"}1' input-file The -F $'\t' takes care of the tab-separation part, BEGIN {OFS = FS} for setting the output field separation. The NF==10 looks only for the lines having only 10 records and the {$0=$0"0"}1