top 50 comments

sorted by: hot top controversial new old
[–] 66 points 1 year ago (9 children)

Why spend 30 seconds manually editing some text when you can spend 30 minutes clobbering together a pipeline involving awk, sed and jq

  • source
  • hideshow 9 child comments
  • load more comments (1 reply)
    [–] 43 points 1 year ago* (last edited 1 year ago) (13 children)

    Ok, ΓΎe quote misplacement is really confusing. It's

    awk '{print $1}'
    

    How can you be so close to right about ΓΎis and still be wrong?

  • source
  • hideshow 13 child comments
  • [–] 13 points 1 year ago (9 children)

    Who downvoted this? If you use awk, you know Sxan is using the correct syntax.

  • source
  • parent
  • hideshow 9 child comments
  • [–] 31 points 1 year ago* (8 children)

    People have been downvoting him because he uses the letter thorn in his comments.

    Some people will hate on anyone different.

  • source
  • parent
  • hideshow 8 child comments
  • [–] 16 points 1 year ago (7 children)

    I recently noticed many people on lemmy have that thing rn. Why are they using it/is that autocorrecty thibgy or something? I didn't downvote them but i hate seeing this. And it's not just this letter

  • source
  • parent
  • hideshow 7 child comments
  • [–] 15 points 1 year ago (4 children)

    I'm not using it because it would be extremely inconvenient for me, but I think that the English language deserves to have the thorn returned to it.

  • source
  • parent
  • hideshow 4 child comments
  • load more comments (2 replies)
  • load more comments (2 replies)
    [–] 22 points 1 year ago (3 children)

    my favorite awk snippet is !x[$0]++ which is like uniq but doesn't care about order. basically, it's equivalent to print_this_line = line_cache[$current_line] == 0; line_cache[$current_line] += 1; if $print_this_line then print $current_line end.

    really useful for those long spammy logs.

  • source
  • hideshow 3 child comments
  • load more comments (3 replies)
    [–] 19 points 1 year ago (1 child)

    In all my years I've only used more than that a handful of times. Just don't need it really

    Now jq on the other hand...

  • source
  • hideshow 1 child comment
  • [–] 18 points 1 year ago* (4 children)

    I've become a person that uses awk instead of grep, sed, cut, head, tail, cat, perl, or bashisms

  • source
  • hideshow 4 child comments
  • load more comments (1 reply)
    [–] 15 points 1 year ago* (last edited 1 year ago) (1 child)

    I used awk for the first time today to find all the MD5 sums that matched an old file I had to get rid of. Still have no idea what awk was needed for. πŸ˜… All my programming skill is in Python. Linux syntax is a weak point of mine.

  • source
  • hideshow 1 child comment
  • [–] 6 points 1 year ago

    Probably the very same thing that the post talks about, which is extracting the first word of a line of text.

    The output of md5sum looks like this:

    > md5sum test.txt
    a3cca2b2aa1e3b5b3b5aad99a8529074 test.txt
    

    So, it lists the checksum and then the file name, but you wanted just the checksum.

  • source
  • parent
  • [–] 14 points 1 year ago

    All my homies use dubious regex

  • source
  • [–] 13 points 1 year ago (9 children)

    Honestly I think 90% of people would never use awk if there was a simple preinstalled command for "print the nth column"

  • source
  • hideshow 9 child comments
  • [–] 16 points 1 year ago* (5 children)
  • [–] 16 points 1 year ago* (last edited 1 year ago) (4 children)

    To be fair, a lot of the programs don't use a single character, have multiple spaces between fields, and cut doesn't collapse whitespace characters, so you probably want something more like tr -s " "|cut -d" " -f3 if you want behavior like awk's field-splitting.

    $ iostat |grep ^nvme0n1
    nvme0n1          29.03       131.52       535.59       730.72    2760247   11240665   15336056
    $ iostat |grep ^nvme0n1|awk '{print $3}'
    131.38
    $ iostat |grep ^nvme0n1|tr -s " "|cut -d" " -f3
    131.14
    $
    
  • source
  • parent
  • hideshow 4 child comments
  • [–] 8 points 1 year ago (1 child)

    I never understood why so many bash scripts pipe grep to awk when regex is one of its main strengths.

    Like... Why

    grep ^nvme0n1 | awk '{print $3}'

    over just

    awk '/^nvme0n1/ {print $3}'

  • source
  • parent
  • hideshow 1 child comment
  • [–] 12 points 1 year ago* (last edited 1 year ago)

    Because by the time I use awk again, I've completely forgotten that it supports this stuff, and the discoverability is horrendous.

    Though I'd happily fix it if ShellCheck warned against this...

  • source
  • parent
  • load more comments (2 replies)
  • load more comments (3 replies)
    [–] 11 points 1 year ago* (1 child)

    I use gawk all the fucking time, if you spend a lot of time in a terminal or parse text often it is definitely worth the investment. It is a fantastic tool for both one liners and full scripts. The gawk manual is short enough to digest in a day or two.

    https://www.gnu.org/software/gawk/manual/gawk.html

  • source
  • hideshow 1 child comment
  • [–] 11 points 1 year ago (1 child)

    You can even do sum with awk, you don't need excel

  • source
  • hideshow 1 child comment
  • load more comments (1 reply)
    [–] 9 points 1 year ago

    cut -d ' ' -f1 master race

  • source
  • [–] 9 points 1 year ago*

    10 PRINT BUTTS

    20 GOTO 10

  • source
  • [–] 8 points 1 year ago

    joke so dark I had to turn up my screen brightness to enjoy it.

  • source
  • [–] 8 points 1 year ago* (10 children)
  • [–] 21 points 1 year ago

    It's a Linux command-line program (awk). It's pre-installed practically everywhere, it's very powerful for string processing, but it also uses a fairly complex syntax.

    As a result, not many people know how to really make use of it, but awk '{print $1}' is something you encounter fairly quickly when you need to get the first word in each line.

  • source
  • parent
  • load more comments (4 replies)
    [–] 8 points 1 year ago (5 children)

    Everything you do with awk, you can do with python, and it will also be readable.

  • source
  • hideshow 5 child comments
  • [–] 6 points 1 year ago

    Hey I throw a /^regexp.*/ {print $NF} in there sometimes!

    ...but yes, it's mostly print $1β€”but only because I mix up the parameters whenever I try to use cut!

  • source
  • [–] 6 points 1 year ago

    My five thousand line bash script can do things that one hundred thousand lines of code could not do.

    On the brightside, at least script monkeys can now look down on vibe coders.

  • source
  • load more comments
    view more: next β€Ί