4 ms·
It does not. Compare: $ echo ' 1 2 3' | cut -f2 1 2 3 $ echo ' 1 2 3' | cut -f2 -d' ' $ echo ' 1 2 3' |
by syncsynchalt 7y ago
It does not. Compare:
$ echo ' 1 2 3' | cut -f2
1 2 3
$ echo ' 1 2 3' | cut -f2 -d' '
$ echo ' 1 2 3' | awk '{print $2}'
2
"-f [...] Output fields are separated by a single occurrence of the field delimiter character."
- cauthon 7y agooh yes, totally agree. if the data isn't delimited by a single character, then you definitely need awk or sed+cut
- ratsmack 7y agoAlso, the field separator (FS) can be a regular expression. FS = "[0-9]"
- jerf 7y agoIIRC, there is an invocation of cut that basically does what I want, but every time I try, I read the manual page for 3 or 4 minutes, craft a dozen non-functional command lines, then type "awk '{ print $6 }'" and move on.
- masklinn 7y ago> IIRC, there is an invocation of cut that basically does what I want I don't think there is, because cut separates fields strictly on one instance of the delimiter. Which sometimes works out, but usually doesn't. Most of the time, you have to process the input through sed or tr in order to make it suitable for cut. The most frustrating and asinine part of cut is its behaviour when it has a single field: it keeps printing the input as-is instead of just going off and selecting nothing, or printing a warning, or anything which would bloody well hint let alone tell you something's wrong. Just try it: `ls -l | cut -f 1` and `ls -l | cut -f 13,25-67` show exactly the same thing, which is `ls -l`. cut is a personal hell of mine, every time I try to use it I waste my time and end up frustrated. And now I'm realising that really cut is the one utility which should get rewritten with a working UI. exa and fd and their friends are cool, but I'd guess none of them has wasted as much time as cut.
- timbit42 7y agoecho ' 1 2 3' | tr -s ' ' | cut -b 2- | cut -d' ' -f2 or echo ' 1 2 3' | tr -s ' ' '\t' | cut -b 2- | cut -f2
- catalogia 7y agoPerfect example of how "do one thing and do it well" is a lie.