AWK - A Tool That Does Too Much

Поділитися
Вставка
  • Опубліковано 25 гру 2024

КОМЕНТАРІ • 75

  • @michaelhawthorne5516
    @michaelhawthorne5516 День тому +104

    Awk twah sed on that thang

  • @ericmintz8305
    @ericmintz8305 9 годин тому +5

    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.

  • @69k_gold
    @69k_gold День тому +37

    Awk 2? Ah what a good version

  • @borkomne
    @borkomne 2 години тому +1

    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)

  • @sanderdejong66
    @sanderdejong66 22 години тому +7

    I used to be an awk man, I never used sed. This vid brings back some memories 😊

  • @animanaut
    @animanaut 8 годин тому +4

    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.

  • @martins2246
    @martins2246 День тому +40

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

    • @paulsander5433
      @paulsander5433 День тому +6

      I hope you knew about the "join" and "sort" commands, too. A relational database would be hard to build without them.

    • @ismbks
      @ismbks День тому +9

      perl is awk + sed + the gold standard regex implementation

    • @martins2246
      @martins2246 14 годин тому +1

      @@paulsander5433 probably? it was in c shell lol...wtf

    • @paulsander5433
      @paulsander5433 12 годин тому

      @@martins2246 The sort and join programs aren't shell built-ins, so they're available in csh, too. And they work well in pipelines.

  • @mxm650
    @mxm650 7 годин тому

    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.

  • @milo3733
    @milo3733 День тому +6

    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

  • @SeanCCosgrove
    @SeanCCosgrove 7 годин тому +1

    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.

  • @Soupie62
    @Soupie62 7 годин тому +1

    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.

  • @chrismcgowan3938
    @chrismcgowan3938 15 годин тому +2

    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.

  • @zedzpan
    @zedzpan День тому +8

    Brings back many memories when I stumbled on awk.

  • @GooogleGoglee
    @GooogleGoglee 20 годин тому +1

    awk deserve a playlist just for itself.

  • @anon_y_mousse
    @anon_y_mousse День тому +1

    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.

  • @lel7531
    @lel7531 8 годин тому

    Great video keep it up !!

  • @AdrianBoyko
    @AdrianBoyko День тому +6

    I had a CompSci professor in the early 1990s who called AWK “The Queen of Programming Languages” 😵‍💫

  • @ps-ri2qk
    @ps-ri2qk День тому +4

    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!

    • @kees3125
      @kees3125 День тому +5

      While paused, tap/click on empty area and controls are hidden!

  • @TheNovum
    @TheNovum 23 години тому

    Good video. this is what i like about *nix and *BSD

  • @joeteejoetee
    @joeteejoetee День тому +6

    This very helpful for ole' rusty linux hobbiests like me.
    Liked and subscribed for sure.
    Thanks!

  • @bitti1975
    @bitti1975 День тому +5

    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.

    • @paulsander5433
      @paulsander5433 День тому +2

      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
      @dortechristiansen886 22 години тому

      Speed could be the reason for many grep|awk

    • @bitti1975
      @bitti1975 20 годин тому

      ​@@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.

    • @bitti1975
      @bitti1975 20 годин тому

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

    • @dortechristiansen886
      @dortechristiansen886 15 годин тому +1

      If grep is many times faster to regex it could be faster

  • @LitheInLitotes
    @LitheInLitotes 21 годину тому +4

    Awk makes powershell's objects really desirable by comparison... Too bad ms is evil

  • @Stephen-wc8fn
    @Stephen-wc8fn 9 годин тому

    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.

  • @schlollepop
    @schlollepop 22 години тому +1

    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? 😉

  • @sarundayo
    @sarundayo 9 годин тому

    What's the difference between AWK and GREP?

    • @ulrichberntien2873
      @ulrichberntien2873 27 хвилин тому

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

  • @andreyv116
    @andreyv116 День тому

    Awk is quirky but it sucks less than doing non trivial things with sed

  • @EkShunya
    @EkShunya 3 дні тому +9

    why not talk abt perl as well

    • @TheExhaustedProgrammer
      @TheExhaustedProgrammer  2 дні тому +4

      I'll add it to the list

    • @trueriver1950
      @trueriver1950 День тому +5

      awk is well suited to short one-off scripting in a pipeline
      Anything more complicated then yes: I would use Perl.

    • @ivanheffner2587
      @ivanheffner2587 День тому

      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.

    • @sssxxxttt
      @sssxxxttt День тому

      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…

    • @andreyv116
      @andreyv116 День тому

      Awk is more minimal than Perl but if your things are complex enough then Perl is more maintainable

  • @PaulHewsonPhD
    @PaulHewsonPhD День тому

    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!

  • @CjqNslXUcM
    @CjqNslXUcM Хвилина тому

    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.

  • @danblanks3190
    @danblanks3190 День тому +3

    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.

    • @anon_y_mousse
      @anon_y_mousse День тому +8

      Point to where on the doll Linux touched you. Remember, therapy only works if you allow it to work.

    • @soppaism
      @soppaism День тому +3

      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.

    • @stevevandevender8319
      @stevevandevender8319 23 години тому +6

      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?

    • @danblanks3190
      @danblanks3190 16 годин тому +1

      @@anon_y_mousse 😂😂😂

  • @PiotrRzeszów-c9x
    @PiotrRzeszów-c9x День тому +3

    maybe just use copilot + python?

    • @tracyrreed
      @tracyrreed День тому +12

      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.

    • @inertia_dagger
      @inertia_dagger День тому +4

      no

    • @wrathofainz
      @wrathofainz День тому +4

      Ew, Microsoft

    • @paulsander5433
      @paulsander5433 День тому +2

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

    • @ivanheffner2587
      @ivanheffner2587 22 години тому

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