Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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


> [...] 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


Didn't know about that option, I always did it with sed. Thanks! :)


Apparently, it doesn't reinforce that strategy enough ;-)


Haha, 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…




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: