Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 872
Switch Avatar asked Feb 23 '23 21:02

Switch


1 Answers

sed -r 's/ +/ /g' input.txt|cut -d " " -f 9-
like image 56
Kent Avatar answered Feb 26 '23 21:02

Kent