Does cut support non-white-space to white-space delimeters?

The default delimiter in awk is white-space to non-whitespace change.

The default for cut is the tab character.

Can I tell cut to use non-white-space to white space delimters?

E.g.

a:

foo  bar

cut -d' ' -f2 a

prints just a space, but should print bar.

awk '{ print $2; } a

print bar.

Sure, often you can just use awk as a cut replacement if you need that semantics. But cut has the advantage that it is very memory efficient. Especially it does not load unused columns into memory (unlike some awks).

Asked By: maxschlepzig

||

I don’t see how to make cut(1) do what you want. I believe you are correct in believing that if you have mixed whitespace delimiters that the best alternative is awk(1).

Answered By: Warren Young

You could preprocess your data with something like tr -s ' ' 't'. But you wouldn’t get any benefit unless your lines were very long. (How long? measure and find out.)

Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.