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?
sed -r 's/ +/ /g' input.txt|cut -d " " -f 9-
You could use sed
to replace n
whitespaces with a single whitespace:
sed -r 's/\ +/\ /g' input.txt | cut -d ' ' -f 9-
Just be sure there aren't any tabs between your columns.
精彩评论