Search code examples
linuxcommand-linecut

linux command line: cut (with empty fields)


I have a file (input.txt) with columns of data separated by spaces. I want to get the 9th column of data and onwards.

Normally I would do:

cut -d " " -f 9- input.txt

However, in this file, sometimes the fields are separated by multiple spaces (and the number of spaces varies for each row / column). cut doesn't seem to treat consecutive spaces as one delimiter.

What should I do instead?


Solution

  • sed -r 's/ +/ /g' input.txt|cut -d " " -f 9-