Search code examples
linuxbashshell

How to cut first n and last n columns?


How can I cut off the first n and the last n columns from a tab delimited file?

I tried this to cut first n column. But I have no idea to combine first and last n column

cut -f 1-10 -d "<CTR>v <TAB>" filename

Solution

  • Cut can take several ranges in -f:

    Columns up to 4 and from 7 onwards:

    cut -f -4,7-
    

    or for fields 1,2,5,6 and from 10 onwards:

    cut -f 1,2,5,6,10-
    

    etc