bashshellcut

Does CUT support multiple spaces as the delimiter?


I have text like this:

word1 word2   word3  word4

There may be more than one space between a pair of words and I want to get some columns of words from each line . When I use cat file | cut -d ' ' -f1,2,4 it seems that some fields are space which is not what I expected. I know awk can achieve this. The question is can we do this with cut only? i.e., can we set multiple spaces as the delimiter in cut, yet the number varies?


Solution

  • No, you cannot. If you want to be able to use more than one character (or even a regex) for the delimiter then use awk instead.