Splitting one large file into many if the text in a column doesn't match the text in the one before it

后端 未结 4 1091
无人及你
无人及你 2021-01-26 06:31

I searched for awhile and couldn\'t find a response to this. I have a standard tsv file with the following format:

1    100    101    350    A
1    101    102            


        
4条回答
  •  庸人自扰
    2021-01-26 06:54

    With awk

    awk '{out = "File" $NF ".txt"; print >> out; close(out)}' file
    

    More efficient, not closing the destination file after every line:

    awk '
        $NF != dest {if (out) close(out); dest = $NF; out = "File" dest ".txt"} 
        {print >> out}
    ' file
    

提交回复
热议问题