5 ms·
Every time I go to use awk for something I always think, 'I feel like I would be able to do this with cut so much more easily, but I also know that I always fee
by codyrobbins 17y ago
Every time I go to use awk for something I always think, 'I feel like I would be able to do this with cut so much more easily, but I also know that I always feel like that, but am never able to get cut to actually do what I want.' Despite feeling that way, I usually optimistically go spend 30 minutes trying to get cut to do something simple like give me a specific column from the output of ps aux. But it's just 30 minutes of banging my head against the keyboard, and it always reinforces my original strategy, which is to use awk for everything and never, ever use cut.
- gthank 17y agoApparently, it doesn't reinforce that strategy enough ;-)
- codyrobbins 17y agoHaha, you’re right. The problem is that I really want cut to just do what it sounds like it should do based on its name! Sigh…
- silentbicycle 17y agoIf your issue with cut is what I susect, you need to flatten the whitespace first with sed. At that point, I'd just use awk, though. It has better defaults for field delimiters.
- jsrn 17y ago> [...] you need to flatten the whitespace first with sed by "flatten the whitespace" do you mean turning many spaces into one space? If so, I have always used tr with the -s (squeeze) option for that: $ echo "one two three" | tr -s " " | cut -d " " -f 3 three
- silentbicycle 17y agoDidn't know about that option, I always did it with sed. Thanks! :)