I am trying to parse a table with variable number of delimiters to convert into a table of equal columns cluster=96\troot\tcellular organisms\tno_rank no_rank$cluster=42\troot\tcellular organisms\tBacteria\tno_rank\tno_rank\tsuperkingdom$cluster=362\troot\tcellular organisms\tBacteria\tProteobacteria\tno rank\tno rank\tsuperkingdom\tphylum$cluster=12330\troot\tcellular organisms\tBacteria\tTerrabacteria\tFirmicutes\tClostridia\tClostridiales\tClostridiaceae\tClostridium\tno rank\tno rank\tsuperkingdom\tno rank\tphylum\tclass\torder\tfamily\tgenus$The expected output is:cluster=96\troot\tcellular organisms\t\t\t\t\t\t\t\tno_rank\tno_rank\t\t\t\t\t\t\t$cluster=42\troot\tcellular organisms\tBacteria\t\t\t\t\t\t\tno_rank\tno_rank\tsuperkingdom\t\t\t\t\t\t$cluster=362\troot\tcellular organisms\tBacteria\tProteobacteria\t\t\t\t\t\tno rank\tno rank\tsuperkingdom\tphylum\t\t\t\t\t$cluster=12330\troot\tcellular organisms\tBacteria\tTerrabacteria\tFirmicutes\tClostridia\tClostridiales\tClostridiaceae\tClostridium\tno rank\tno rank\tsuperkingdom\tno rank\tphylum\tclass\torder\tfamily\tgenus$\t is tab delimiter and $ is end of line
sed or awk command to insert tabs (delimiter) at spcific positions
text processing;sed;awk
Using Awk with two passes:awk -F'\t' -v OFS='\t' 'FNR==NR {if (NF>a) {a=NF}; next} NF<a{$a=} 1' file fileThis will add the extra tabs at the end of the lines with missing fields.Based on your exact sample data, I think it is likely you are dealing with a problem impossible to solve programmatically.  If you need extra tabs in an intermediate position to ensure the no_rank values end up in the right column, you will need some fancier logic.