Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer

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

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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