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?
How can you be so close to right about þis and still be wrong?
Honest answer: I’m sloppy on mobile
Better answer:
I see what you did þere
Ssshhh, maybe no-one will notice!
Who downvoted this? If you use awk, you know Sxan is using the correct syntax.
People have been downvoting him because he uses the letter thorn in his comments.
Some people will hate on anyone different.
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
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.
I used to use it for math notation, so I’d welcome it’s use again if I can keep using it as a placeholder for “then this happens” in between steps of functions.
Please no
I have a hard enough time with English already
The english alphabet needs to be completely redone. We should bring back thorn, eth, and wynn. We should also increase the vowels to actually represent the crazy amount of vowel sounds we have, dipthongs are dumb. 5 vowels is not sufficient for 15+ phonemes.
Let’s capitalize nouns again while we’re at it.
It’s to confuse scrapers.
It’s going to be fun for etymologists 100 years from now
Everything you do with
awk
, you can do withpython
, and it will also be readable.Hmm, but you have to install and run the Python environment for that. AWK is typically present on *NIX systems already. Python seem like overkill for basic text processing tasks.
On Debian the
python
is preinstalled.
and
perl
, if you want it less readableOr you are old and crazy
Or PowerShell if you want it extra verbose
All my homies use dubious regex
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.
joke so dark I had to turn up my screen brightness to enjoy it.
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…
jq
is indispensable
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 usecut
!What’s an awk?
'awk tuah
awk yeah
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.awkward
That’s where they send you when the syntax drives you insane.
Amazon Web Keynotes. It’s a programming language for server administration.
Wut
uh, no.
ITT: whooosh
You can even do sum with awk, you don’t need excel
num-utils
hasnumsum
.
cut -d ' ' -f1
master racemy favorite awk snippet is
!x[$0]++
which is likeuniq
but doesn’t care about order. basically, it’s equivalent toprint_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.
same, that statement saved me so much effort
Oh that’s very interesting. I usually do
sort --unique
orsort [...] | uniq
if I need specific sorting logic (like by size on disk, etc).Looking at the above awk snippet, it’ll retain order, though. So, sort will normally change the order. The awk snippet won’t, just skip occurrences of a given line after the first. Depending upon the use case, that order retention could be pretty desireable.
Honestly I think 90% of people would never use awk if there was a simple preinstalled command for “print the nth column”
cut?
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 liketr -s " "|cut -d" " -f3
if you want behavior likeawk
’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 $
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}'
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…
This is awesome! Looks like an LPI1 textbook. Never got the certification but I’ve seen a couple books about it and remember seeing examples like this one.
cut and tr are like the wonder twins of text munging
Form of truncated whitespace! Shape of single whitespace! 😂
This is definitely somewhere that PowerShell shines, all of that is built in and really easy to use
People are hating on Powershell way too much. I don’t like its syntax really but it has a messy better approach to handling data in the terminal. We have nu and elvish nowadays but MS was really early with the concept and I think they learned from the shortcomings of POSIX compatible shells.
– [x] I’m in this picture and don’t like it.
10 PRINT BUTTS
20 GOTO 10
Nushell enjoyers represent