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?



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).


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).


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.)

  • yeah, tr is a good work-around. And yes, I have some weird log files with very long lines (several MB). Don't ask. – maxschlepzig Aug 31 '10 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.