mboelen, to linux
@mboelen@mastodon.social avatar

I'm working on a cheat sheet for . This nifty tool is easily overlooked, but so powerful that it really made me invest more time into learning it.

The initial version of the cheat sheet is available and ready for feedback: https://linux-audit.com/cheat-sheets/awk/

Boosts would be appreciated, and feedback even more!

What are your AWK one-liners that others really need to know and should be included?

Special thanks to @DopeGhoti

juandesant, to random
@juandesant@astrodon.social avatar

I tend to follow the logic of awk better than the one of sed (not being a vi enthusiast), but it is good to see when one might be better than the other:

https://www.linuxjournal.com/content/text-manipulation-linux-awk-vs-sed

sergio_101, to ChatGPT
@sergio_101@mastodon.social avatar

for like more than 30 years, i have kinda skirted writing serious , getting good with and , and getting really good with because it usually meant a TON of digging through old documentation and piecing things together. Recently, i just started asking things like:

How do I flip through a directory of a bazillion zip files, uncompress each one, put the contents on my NAS, and then move those zip files somewhere else for safekeeping?

and learn from the answer

jacobydave, to random
@jacobydave@mastodon.xyz avatar

I use sed and awk enough to know I should use them, but not enough to know, necessarily, whether it's sed or awk I need at any specific instance.

mjgardner,
@mjgardner@social.sdf.org avatar

@jacobydave when your data has records (lines) and fields (columns).

when it doesn’t.

Combine to taste.

And when you get tired of smushing everything through text pipes or cross-platform differences forcing portable code down to the least-common denominator of features, do what @cestith said and use : https://mastodon.social/@cestith/111857559756385921

awb, to linux

Another interesting AWK feature(?) that is likely little known is that there can be any number of BEGIN and END patterns and they can be anywhere in the AWK program. Their statements are concatenated into one action at run-time.

This makes me wonder, has anybody a) ever seen this used in production code and b) why?
#awk #unix #linux

ChristosArgyrop, to php
@ChristosArgyrop@mstdn.science avatar

I think I am 50% done finding a quadrafecta : a simultaneous hit piece against & .

This one only manages to trash talk and , so it has some ways to go.

https://stefanoborini.com/why-r-is-the-new-perl/

PS 1Gotta admit that the point about the object systems in R is somewhat spot on
PS 2 gets a dishonorable mention
PS3 I will continue to find ways to continue using all 4 of the aforementioned languages, as they are all performant and deliver in complementary ways.

mjgardner,
@mjgardner@social.sdf.org avatar

@ChristosArgyrop @BobOHara By "happily derivative," Larry meant that intentionally resembles other languages and tools.

In context, he was responding in 1992 (Perl's current version was 4.035) to @bduncan whinging, “It's sorta like , but not. It's sorta like , but not.” https://groups.google.com/g/comp.unix.shell/c/J8fGo0oGUCk/m/LhF4pSEaOMwJ

mjgardner,
@mjgardner@social.sdf.org avatar

@Edwardsmoon @ChristosArgyrop @BobOHara @bduncan Yes, deliberately borrows familiar things from culture, including #C, , , and . The goal isn’t necessarily to replace them, but to remove friction when combining their capabilities.

@randalschwartz's Perl solutions to Unix questions usually demonstrated such reductions.

mjgardner,
@mjgardner@social.sdf.org avatar
mjgardner,
@mjgardner@social.sdf.org avatar

@ChristosArgyrop @Edwardsmoon @BobOHara So… fashion and received wisdom traced back to the turn-of-the-century boom in shitty , supported by the belief that they're protected from building a shitty melange of , , , , and ?

mjgardner, to programming
@mjgardner@social.sdf.org avatar

@Perl Happy 36th to the language!

v1.0 then:
“Perl is kind of designed to make and semi-obsolete […] The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).” https://github.com/Perl/perl5/releases/tag/perl-1.0

v5.38.2 now:
“Perl is […] now used for a wide range of tasks including , , network programming, development, and more.” https://perldoc.perl.org/perlintro#What-is-Perl%3F

mjgardner,
@mjgardner@social.sdf.org avatar

@sjfloat @Perl When you get tired of escaping metacharacters in your and pipelines, when you get tired of inventing new ways to pass structured data between small tools as text streams, is there.

Of course, you can take that last point too far. See or even , where half the “fun” is marshalling between bespoke data structures.

mjgardner, (edited )
@mjgardner@social.sdf.org avatar

@adrianco @Perl I hope your script only uses the subset supported by a2p: https://metacpan.org/pod/App::a2p

Also, it hasn’t been included with for eight years. @leont has been looking for a new maintainer for three.

SweetAIBelle, to random

This might sound silly, but I installed virt-manager to make things a little easier when using qemu, then created a new virtual machine with debian 12 on it... then installed qemu on that.

The actual reason for this is to make github account separation a little easier...

If you get virt-manager set up properly, it definitely makes using qemu easier, though. I practically just had to tell it to make a new virtual machine using this iso with this much memory and this big of a hard drive, and it was right at the debian install screen. (Set it up with xfce...).

Main tricky parts were that I had to install libvirt first, make myself a member of the libvirt user group, enable the service, and install dnsmasq. Not great, but could've been worse...

Used debian on the virtual box just for a little variety. I like to keep my hand in on different distributions a bit.

kkarhan,
@kkarhan@mstdn.social avatar

U mean, peaople say / is hard, but compared to it's like & compared to using / & to write mathematical formulas in by hand on a Teletype...

But then again those that can do the latter really know their shit backwards and upside down so hats off to them...
https://www.youtube.com/watch?v=XGo4PJd1lng&t=195s

bytephantom, to infosec
kkarhan,
@kkarhan@mstdn.social avatar

@bytephantom /me *points towards #ne because #emacs is #bloatware, #vi / #vim / #neovim ain't noob-friendy and people using #sed & #awk to edit files are like #GalaxyBrainChair - type of #NextLevel...

Also it has a cool #TUI with menus so even better than #nano.
https://ne.di.unimi.it/

awb, to linux

AWK was designed to harmoniously integrate with the Shell and follow the Unix philosophy. Perl and to some degree Ruby offer that as well. The ease with which a single line AWK script can be integrated in a Shell pipeline is what keeps it alive. Python very much does not offer that, Python scripts are standalone programs.

What other languages are out there that can do something as simple as 'print $2' in a Shell pipeline? jq comes to mind.

cazabon,

@awb

#cut is arguably the one most specifically suited to the task, and much lighter-weight than .

Though you could also just do it in the itself with builtins.

tivasyk, to Bash
@tivasyk@mastodon.social avatar

through all of my sysadmin experience i've been using and avoiding … for some reason. scratch that: for no good reason.

awk is to sed what python is to brainfuck.

the awk programs are a lot more easy to compose and modify, flexible and readable. and there's a brilliant book by the authors — now awailable for a free read from archive.org!

in retrospect, i can't see any tasks that i should have done with sed instead of / awk.

ljrk, to random
@ljrk@todon.eu avatar

Finally my #AWK Programming Language, 2nd Ed., is arriving <3

drincruz, to Bash
@drincruz@mas.to avatar

i recently found out about sadservers.com which is entertaining and allows me to write like this!

awk '{print $1}' /home/admin/access.log | sort | uniq -c | sort

awb, (edited )

@e38383 @botvolution Fun fact, you can also write it like this: awk '{print $1 | "sort | uniq -c | sort -n"}' /home/admin/access.log
#awk #shell

SeaGL, to random
@SeaGL@mastodon.social avatar

Talk announcement for
@FLOX_advocate presents: "Advanced jq: awk for JSON".
Details: https://osem.seagl.org/conferences/seagl2023/program/proposals/950

jartigag, to random

#AWK magic 😇

video/mp4

simondassow, to random

Sometimes I still have fun with :

use Socket qw( inet_pton AF_INET AF_INET6 );

sub sort_ips {
my %ips = map +( $, inet_pton( m!:! ? AF_INET6 : AF_INET, $ ) ), @_;

return sort { $ips{ $a } cmp $ips{ $b } } keys %ips;
}

mjgardner, (edited )
@mjgardner@social.sdf.org avatar

@leonerd @simondassow @Perl @randalschwartz Well, that makes this + one-liner almost trivial:

( arp -na | awk '{print substr($2, 2, length($2) - 2)}';  
 ndp -na | tail +2 | awk '{print $1}' ) |  
 perl -MList::UtilsBy=sort_by -MSocket=inet_pton,AF_INET,AF_INET6 -e '  
 print for sort_by {chomp; inet_pton /:/ ? AF_INET6 : AF_INET, $_} &lt;&gt;'  
root42, to random
@root42@chaos.social avatar

The new #awk programming manual is out!

chakuari, to random Italian
@chakuari@mastodon.bida.im avatar

Added #abook to #neomutt. Great tools!
#OpenBSD

kkarhan,
@kkarhan@mstdn.social avatar

@chakuari OFC.

In theory offering more than just one is "trivial" in the sense that for OS/1337 the idea is to have statical binaries (and maybe the few necessary configs) as "" so it's just a download as an archive ( because it's available in ) and just pull that and place them in the system.

OFC absolute hardcore folks will literally do just with , , & I guess, but ideally offering a convenient alternative like is better.

wh0x3r, to python Portuguese
@wh0x3r@mastodon.social avatar

programando em e pensando como é tão familiar com php

parece uma fusão de +

mjgardner,
@mjgardner@social.sdf.org avatar
  • All
  • Subscribed
  • Moderated
  • Favorites
  • provamag3
  • rosin
  • thenastyranch
  • Durango
  • DreamBathrooms
  • ngwrru68w68
  • magazineikmin
  • cubers
  • Youngstown
  • mdbf
  • slotface
  • osvaldo12
  • GTA5RPClips
  • kavyap
  • megavids
  • InstantRegret
  • everett
  • tacticalgear
  • vwfavf
  • tester
  • normalnudes
  • modclub
  • ethstaker
  • khanakhh
  • cisconetworking
  • anitta
  • Leos
  • JUstTest
  • All magazines