Of all the languages I barely know and seldom use, AWK is by far and away my favorite. I seldom need it, but when need arises, nothing else will do, so I open the manual and code. Plus I know two of the three gentlemen of the old school who wrote the original, and they are beyond awesome.
Great video! I use awk a lot, and this what you presented here is what I use most of the time. There are 2 useful variables in awk I use often: NR - Number of current Record (useful to skip lines if there is a header in file) NF - Number of Fields in a current record (useful to figure out which lines are missing data)
imo one of the most overlooked feature of awk is the record separator. default is just newline, but some files have multiline entries or optional lines with additional information. It helped me once to parse log files that had regular log lines intermixed with lines of stacktraces.
Thanks for the quick overview! I wish this video had been out 10 days ago! I used to use awk a fair amount, but that was 15 or 20 years ago. I needed it last week, but I forgot all the syntax. It took a few hours of looking at man pages and searching to getting the basic syntax right. Worth it, though.
great introduction to awk, i always knew you could print columns but not much else. made me realize i've probably piped sed outputs into awk where I could have done it all in the awk command
One of the features i find very powerful is that the field separator does not need to be a single character (put the default if any amount of whitespace), but can be a regex. Very handy even just for things where one column is separated by whitespace, but you also want to extract something delimited by ":" for example. I use awk too much, but only a small percentage of what it can do.
Stock trading data includes: name, Open, High, Low, Close, and Volume. If you only care about Close, awkward will easily filter out unwanted data. If you only want particular shares, filter for lines starting with specific codes.
awk is one of my favourite languages. The language itself is very 'C' like, and I always found it easy to use, except for a few weird quirks. My main use of awk is to extract data out of huge amounts of text files, and on the command line for simple tasks. I think that awk is one of the most brilliant little tools that came out of the NIX word.
I use awk in my .bashrc to filter various commands. For example, I print only the relevant drives from df's output and I make sure the header still prints out. Since I use a pattern for the type of drives to display, it even works with flash drives and external hard drives too.
Thanks for the Aho Weinberger Kernighan formatting/scripting tool video. I remember/forget this from the O'reilly books in the 90's. While trying to follow along on YT and pausing the video the lower area has this red line with controls, obfuscating the bottom 1/2" or so. Would you consider formatting it so the commands are well above the bottom area of the video? Then when it's paused it would be easily readable to look at in detail. Thanks again!
I hope what people will gain from this is that awk can do much more than just printing columns. I can't count how often I see a `grep ... | awk ...` pipeline. Eh? Awk can select lines by regex... Unless you need a very specific grep feature there is no reason to do that.
Regretfully, awk doesn't seem to recognize extended regular expressions. That would be a legitimate use of grep before awk in a pipeline, but then it would probably be egrep rather than grep.
@@dortechristiansen886 'Speed' regarding 'no time to think'? Clearly you can not mean performance, since invoking two programs (and another subshell) is of course slower than just one.
@@paulsander5433 I'm not sure what you mean. The original AWK (BSD/macOS) manpage says: "Regular expressions are as in egrep; see grep(1)." and GNU AWK's manpage says "Regular expressions are essentially the same as those in egrep(1).", so the most common AWK versions in use should support the same regexes as egrep.
This brings to mind my biggest disappointment: Unix should have used tabs for column separation rather than spaces. A Unix tool chain built on tab and nl would have made text parsing so much easier.
Ah, the only write-only language ever invented. At some point, I gave up debugging awk scripts and just rewrote them from scratch if they did not work. The word “awkward” is derived from that language, right? 😉
`grep` is a good simple tool with a single function: Search for a text pattern in an input stream (input file). The output is limited to selected parts of the input, also counting in output is possible. The `awk` tool can also check for text patterns in an input stream. It can also take over the function of `grep`. In addition, `awk` can process the text, store parts of the text in variables, use these variables, perform calculations with numbers from the input, write to various output files. The `awk` programming language is a real programming language. There are `awk` programs on the web, e.g. a Sudoko solver.
I think this video showed up in my feed because earlier today I said: What do you get when you implement sed and awk in ksh? Perl 4. IIRC Larry Wall wrote Perl to combine multiple tools into one scripting language without so many pipelines. It made a pretty good programming language for a while, too.
I still struggle to use awk where appropriate hoping one day I may get fluent. But one thing always beats me, csv files that have commas embedded within a quoted text field. Nice video!
Awk and sed are a nightmare, because parsing strings is a nightmare. The collective time and effort put into parsing when all you should have to do is query a field haunts me. String parsing is flimsy, and it is difficult to deal with edge cases. Tiny changes in output break everything, and worst of all, commands often fail silently, by which I mean it parses something unintended, making debugging sisyphusian labor. Sed and awk's are syntax are arcane, and an untransferable skill. A humungous waste of time caused by bad archictectural desisions, tech debt and elitists unwilling to change. jq is a well intentioned step in the right direction, but nothing more than a stopgap on the way to a typed shell. It's embarrassing how rotten to the core linux shells are, while windows has powershell.
It was commands like awk, clearly designed by committees of committees packed with a dizzying array of options, that make me so glad that I never have to work on a Linux system ever again for the rest of my life.
I think it's the exact opposite of that. If you want to get as much done as possible while memorizing as little weird syntax as possible, awk is one of the best choices out there.
As pointed out in the video, awk was developed as part of the original UNIX in the 1970s when Linus Torvalds was still a toddler, and it's named after its original authors, Aho (co-author of a famous textbook "Principles of Compiler Design"), Weinberger, and Kernighan (who co-wrote "The C Programming Langugage" with Dennis Ritche and "The UNIX Programming Environment" with Rob Pike). So a committee of three, perhaps?
awk is a lot faster to whip up a one liner to do something like parse a process list vs opening a pipe from ps in Python and parsing that. Awk is everywhere and although python is pretty common these days you can't count on it being installed everywhere. Particularly inside busybox or a container. Plus, MS stinks. I don't want to put on those handcuffs.
@@tracyrreed The other problem with Python is that it's not source code compatible with Python. Every few minor releases, they change or remove a feature that breaks existing scripts. They didn't learn from Perl's early mistakes. Ruby has the same problem. Awk, sed, bash, ksh, and other languages generally don't have that problem.
@@PiotrRzeszów-c9x Or you could try being a decent programmer with an actual understanding of the tools you use rather than being next generation of skript kiddie reliant on GIGO LLM to do your job.
Awk twah sed on that thang
Slept on lol
ok thats it im ending it
lol
+2
You wget me?
Of all the languages I barely know and seldom use, AWK is by far and away my favorite. I seldom need it, but when need arises, nothing else will do, so I open the manual and code. Plus I know two of the three gentlemen of the old school who wrote the original, and they are beyond awesome.
Awk 2? Ah what a good version
also known as C awk
awk tuah
C what you did there
Great video!
I use awk a lot, and this what you presented here is what I use most of the time.
There are 2 useful variables in awk I use often:
NR - Number of current Record (useful to skip lines if there is a header in file)
NF - Number of Fields in a current record (useful to figure out which lines are missing data)
I used to be an awk man, I never used sed. This vid brings back some memories 😊
imo one of the most overlooked feature of awk is the record separator. default is just newline, but some files have multiline entries or optional lines with additional information. It helped me once to parse log files that had regular log lines intermixed with lines of stacktraces.
"awk and sed"...those two always seem to be together. I made a relational db with csv's, awk and sed in an airgapped secuirty zone.
I hope you knew about the "join" and "sort" commands, too. A relational database would be hard to build without them.
perl is awk + sed + the gold standard regex implementation
@@paulsander5433 probably? it was in c shell lol...wtf
@@martins2246 The sort and join programs aren't shell built-ins, so they're available in csh, too. And they work well in pipelines.
Thanks for the quick overview! I wish this video had been out 10 days ago!
I used to use awk a fair amount, but that was 15 or 20 years ago. I needed it last week, but I forgot all the syntax. It took a few hours of looking at man pages and searching to getting the basic syntax right. Worth it, though.
great introduction to awk, i always knew you could print columns but not much else. made me realize i've probably piped sed outputs into awk where I could have done it all in the awk command
One of the features i find very powerful is that the field separator does not need to be a single character (put the default if any amount of whitespace), but can be a regex. Very handy even just for things where one column is separated by whitespace, but you also want to extract something delimited by ":" for example. I use awk too much, but only a small percentage of what it can do.
Stock trading data includes: name, Open, High, Low, Close, and Volume.
If you only care about Close, awkward will easily filter out unwanted data.
If you only want particular shares, filter for lines starting with specific codes.
awk is one of my favourite languages. The language itself is very 'C' like, and I always found it easy to use, except for a few weird quirks. My main use of awk is to extract data out of huge amounts of text files, and on the command line for simple tasks. I think that awk is one of the most brilliant little tools that came out of the NIX word.
Brings back many memories when I stumbled on awk.
awk deserve a playlist just for itself.
I use awk in my .bashrc to filter various commands. For example, I print only the relevant drives from df's output and I make sure the header still prints out. Since I use a pattern for the type of drives to display, it even works with flash drives and external hard drives too.
Great video keep it up !!
I had a CompSci professor in the early 1990s who called AWK “The Queen of Programming Languages” 😵💫
He was not wrong.
Thanks for the Aho Weinberger Kernighan formatting/scripting tool video. I remember/forget this from the O'reilly books in the 90's. While trying to follow along on YT and pausing the video the lower area has this red line with controls, obfuscating the bottom 1/2" or so. Would you consider formatting it so the commands are well above the bottom area of the video? Then when it's paused it would be easily readable to look at in detail. Thanks again!
While paused, tap/click on empty area and controls are hidden!
Good video. this is what i like about *nix and *BSD
This very helpful for ole' rusty linux hobbiests like me.
Liked and subscribed for sure.
Thanks!
I hope what people will gain from this is that awk can do much more than just printing columns. I can't count how often I see a `grep ... | awk ...` pipeline. Eh? Awk can select lines by regex... Unless you need a very specific grep feature there is no reason to do that.
Regretfully, awk doesn't seem to recognize extended regular expressions. That would be a legitimate use of grep before awk in a pipeline, but then it would probably be egrep rather than grep.
Speed could be the reason for many grep|awk
@@dortechristiansen886 'Speed' regarding 'no time to think'? Clearly you can not mean performance, since invoking two programs (and another subshell) is of course slower than just one.
@@paulsander5433 I'm not sure what you mean. The original AWK (BSD/macOS) manpage says: "Regular expressions are as in egrep; see grep(1)." and GNU AWK's manpage says "Regular expressions are essentially the same as those in egrep(1).", so the most common AWK versions in use should support the same regexes as egrep.
If grep is many times faster to regex it could be faster
Awk makes powershell's objects really desirable by comparison... Too bad ms is evil
This brings to mind my biggest disappointment: Unix should have used tabs for column separation rather than spaces. A Unix tool chain built on tab and nl would have made text parsing so much easier.
Ah, the only write-only language ever invented. At some point, I gave up debugging awk scripts and just rewrote them from scratch if they did not work.
The word “awkward” is derived from that language, right? 😉
What's the difference between AWK and GREP?
`grep` is a good simple tool with a single function: Search for a text pattern in an input stream (input file). The output is limited to selected parts of the input, also counting in output is possible.
The `awk` tool can also check for text patterns in an input stream. It can also take over the function of `grep`.
In addition, `awk` can process the text, store parts of the text in variables, use these variables, perform calculations with numbers from the input, write to various output files. The `awk` programming language is a real programming language. There are `awk` programs on the web, e.g. a Sudoko solver.
Awk is quirky but it sucks less than doing non trivial things with sed
why not talk abt perl as well
I'll add it to the list
awk is well suited to short one-off scripting in a pipeline
Anything more complicated then yes: I would use Perl.
I think this video showed up in my feed because earlier today I said: What do you get when you implement sed and awk in ksh? Perl 4.
IIRC Larry Wall wrote Perl to combine multiple tools into one scripting language without so many pipelines. It made a pretty good programming language for a while, too.
I skipped awk, except for being able to read it. If I can’t do it in sed I go to perl. Admittedly heavier but with hw of today…
Awk is more minimal than Perl but if your things are complex enough then Perl is more maintainable
I still struggle to use awk where appropriate hoping one day I may get fluent. But one thing always beats me, csv files that have commas embedded within a quoted text field. Nice video!
Awk and sed are a nightmare, because parsing strings is a nightmare. The collective time and effort put into parsing when all you should have to do is query a field haunts me.
String parsing is flimsy, and it is difficult to deal with edge cases. Tiny changes in output break everything, and worst of all, commands often fail silently, by which I mean it parses something unintended, making debugging sisyphusian labor.
Sed and awk's are syntax are arcane, and an untransferable skill. A humungous waste of time caused by bad archictectural desisions, tech debt and elitists unwilling to change. jq is a well intentioned step in the right direction, but nothing more than a stopgap on the way to a typed shell. It's embarrassing how rotten to the core linux shells are, while windows has powershell.
It was commands like awk, clearly designed by committees of committees packed with a dizzying array of options, that make me so glad that I never have to work on a Linux system ever again for the rest of my life.
Point to where on the doll Linux touched you. Remember, therapy only works if you allow it to work.
I think it's the exact opposite of that. If you want to get as much done as possible while memorizing as little weird syntax as possible, awk is one of the best choices out there.
As pointed out in the video, awk was developed as part of the original UNIX in the 1970s when Linus Torvalds was still a toddler, and it's named after its original authors, Aho (co-author of a famous textbook "Principles of Compiler Design"), Weinberger, and Kernighan (who co-wrote "The C Programming Langugage" with Dennis Ritche and "The UNIX Programming Environment" with Rob Pike). So a committee of three, perhaps?
@@anon_y_mousse 😂😂😂
maybe just use copilot + python?
awk is a lot faster to whip up a one liner to do something like parse a process list vs opening a pipe from ps in Python and parsing that. Awk is everywhere and although python is pretty common these days you can't count on it being installed everywhere. Particularly inside busybox or a container.
Plus, MS stinks. I don't want to put on those handcuffs.
no
Ew, Microsoft
@@tracyrreed The other problem with Python is that it's not source code compatible with Python. Every few minor releases, they change or remove a feature that breaks existing scripts. They didn't learn from Perl's early mistakes. Ruby has the same problem. Awk, sed, bash, ksh, and other languages generally don't have that problem.
@@PiotrRzeszów-c9x Or you could try being a decent programmer with an actual understanding of the tools you use rather than being next generation of skript kiddie reliant on GIGO LLM to do your job.