3 ms·
>Hard to beat: awk '{ print $1; }' How about: cut -f 1 -d ' ' You don't even need the -d flag if the you happen to be able to use the default delimiter, like
by cyborgx7 9y ago
>Hard to beat: awk '{ print $1; }'
How about: cut -f 1 -d ' '
You don't even need the -d flag if the you happen to be able to use the default delimiter, like in your example.
- zb 9y agoI used to regularly do ad-hoc text processing, typically on a 24 hour log of GPS data (on an early-2000s-era computer). Surprisingly enough, awk is many times faster than cut for any data set big enough for you to notice time passing.
- deleted 9y ago[deleted]
- fnord123 9y agoAwk delimits on whitespace by default. cut cannot do that afaict. So if you have something like this cut wont work: apples 1 bananas 2
- ninkendo 9y agoExactly, which makes cut kinda shit for 99% of common "split-on-whitespace" tasks IMO.
- dredmorbius 9y agoYou can always use awk with IFS/OFS values to clean up the delimiters so you can pass the data off to cut ;-)