Learning Awk Is Essential For Linux Users

Sdílet
Vložit
  • čas přidán 15. 06. 2021
  • One of my favorite command line utilities is "awk" which is a text-processing program. It is mostly used for pattern scanning and processing. In this video, I will give examples of some of the basic awk commands, and show you some of the ways that I often use awk.
    REFERENCED:
    ► www.gnu.org/software/gawk/man... - GNU Awk
    WANT TO SUPPORT THE CHANNEL?
    💰 Patreon: / distrotube
    💳 Paypal: www.paypal.com/cgi-bin/webscr...
    🛍️ Amazon: amzn.to/2RotFFi
    👕 Teespring: teespring.com/stores/distrotube
    DONATE CRYPTO:
    💰 Bitcoin: 1Mp6ebz5bNcjNFW7XWHVht36SkiLoxPKoX
    🐶 Dogecoin: D5fpRD1JRoBFPDXSBocRTp8W9uKzfwLFAu
    📕 LBC: bMfA2c3zmcLxPCpyPcrykLvMhZ7A5mQuhJ
    SOCIAL PLATFORMS:
    🗨️ Mastodon: distrotoot.com/@derek
    👫 Reddit: / distrotube
    📽️ LBRY/Odysee: odysee.com/$/invite/@DistroTu...
    DT ON THE WEB:
    🕸️ Website: distrotube.com/
    🐿️ Gemini Capsule: gemini://distro.tube
    📁 GitLab: gitlab.com/dwt1
    FREE AND OPEN SOURCE SOFTWARE THAT I USE:
    🌐 Brave Browser - brave.com/dis872
    📽️ Open Broadcaster Software: obsproject.com/
    🎬 Kdenlive: kdenlive.org
    🎨 GIMP: www.gimp.org/
    🎵 Audacity: www.audacityteam.org/
    💻 VirtualBox: www.virtualbox.org/
    🗒️ Doom Emacs: github.com/hlissner/doom-emacs
    Your support is very much appreciated. Thanks, guys!
  • Věda a technologie

Komentáře • 412

  • @TecnocraciaLTDA
    @TecnocraciaLTDA Před 2 lety +338

    AWK is not just a text processing utility, awk is a complete programming language!!

    • @TheSulross
      @TheSulross Před 2 lety +28

      yes, remove Perl, Python, and Node JS (notice no mention of Ruby - ah how far they do fall) - awk and bash is all you need

    • @ziggyspaz
      @ziggyspaz Před 2 lety +13

      @@TheSulross you need Perl to keep your sanity, you can remove the rest

    • @gordongoodman8342
      @gordongoodman8342 Před 2 lety +17

      Calm down. It's not that exciting.

    • @TecnocraciaLTDA
      @TecnocraciaLTDA Před 2 lety +15

      @@gordongoodman8342 it is, a lot!

    • @tekvax01
      @tekvax01 Před 2 lety +9

      yup! I was going to comment the same thing. you could even use it as your shell.

  • @SPSHOfficial
    @SPSHOfficial Před 2 lety +110

    At 8min, when you pipe uniq, note that 'uniq' does not detect repeated lines unless they are adjacent.
    You may want to sort the input first, or use 'sort -u' without 'uniq'.
    so it would be | sort | uniq OR | sort -u

  • @JosephSaintClair
    @JosephSaintClair Před 2 lety +164

    awk is a must. So powerful.
    Btw. You actually did just square. Not square root :)

    • @itsalivevideo
      @itsalivevideo Před rokem +13

      Could have done the square root of i*i is i

    • @baruchben-david4196
      @baruchben-david4196 Před rokem +2

      I tried it with sqrt(i) and that worked. I kind of wonder how much math you can do with awk... Yes, exp(var), log(var), cos(var), sin(var) - but not tan(var); var**x gave exponent, as did var^x. Lots of different functions...

    • @sachindeshpande1
      @sachindeshpande1 Před rokem +4

      I have poorest knowledge of maths but I paused and rushed to comment section to check I am not wrong. But tutorial is very good.

  • @erics7004
    @erics7004 Před 2 lety +217

    DT: AWK is important for linux users
    Luke Smith 1 hour later: Why AWK is useless for linux users

    • @charlessmith5465
      @charlessmith5465 Před 2 lety +32

      _Awk is the predictable result of misguided Enlightenment philosophies._ 🤭

    • @PS3PCDJ
      @PS3PCDJ Před 2 lety +40

      Brodie 2 hours later: Boomers fighting over usefulness of linux utilities

    • @TarebossT
      @TarebossT Před 2 lety +20

      _Why learning awk when you can learn grep_

    • @blogattacker
      @blogattacker Před 2 lety +25

      Luke Smith 1 hour later: "You can replace Awk with Emacs"
      10hs later: "You can replace your wife with Emacs"

    • @elderberry-hamster
      @elderberry-hamster Před 2 lety +4

      @@blogattacker 10.5 hours later...I did. 😂

  • @BrutusHiatus
    @BrutusHiatus Před rokem +30

    This is a great tutorial about awk. I've learned quite a bit. The only thing that red flagged me was that NONE of those were square roots. They were squares.

    • @edwardonsax9919
      @edwardonsax9919 Před 10 měsíci

      I just posted this same thing, before seeing you posted it.

    • @danieldevito414
      @danieldevito414 Před 6 měsíci +1

      He just got the order backwards. "The square root of i*i is i". Anyone could have made that mistake.

  • @OscarFURIOUS
    @OscarFURIOUS Před 2 lety +40

    I just came to say that I can see that you listened to the comments and now you are sharing your knowledge on simple but technical stuff that's really helpfull. I apreciate that and also can feel that effort

  • @jeffcauhape6880
    @jeffcauhape6880 Před 2 lety +16

    That is the most clear demonstration of AWK I have ever seen. Amazing.

  • @ecavero1
    @ecavero1 Před 2 lety +142

    In the square root example, very time DT said square root, he means square!
    Great video, DT!

    • @antoninperonnet6138
      @antoninperonnet6138 Před 2 lety +9

      Just swap the 2 fields and pretend you didn't see that:
      "10 is the square root of 100" is a completely valid statement 😃

    • @ecavero1
      @ecavero1 Před 2 lety

      @@antoninperonnet6138
      I could do that! 😉

    • @KeithPeters
      @KeithPeters Před 2 lety +6

      It's AWK math

    • @pleaseenteraname1215
      @pleaseenteraname1215 Před 2 lety

      @@KeithPeters 🤣🤣🤣🤣

  • @tarekrahman1
    @tarekrahman1 Před 2 lety +4

    Glad you made this video. I was stumbling upon awk in everywhere and wanted to learn it but didn't have time to do so. Thanks

  • @intrepidca80
    @intrepidca80 Před 2 lety +34

    14:00 - /^[b,c]/ matches anything that begins with a "b" or a "c" *or a comma*.

  • @4lc0h0l
    @4lc0h0l Před 2 lety +2

    This is great, this video arrived just in time since currently I am on problem automating a lot of stuff with bash scripting and using awk for text-processing. Thanks for the content!

  • @gwgux
    @gwgux Před 2 lety +2

    This is one of the best explanations of awk I've seen! I'll save this one for some people I know that are still just learning Linux.

  • @DaveRogersEsq
    @DaveRogersEsq Před rokem

    Needed a quick refresher on awk as I had no used it in years. This was a great video, covering the essentials. Cheers.

  • @driden1987
    @driden1987 Před 2 lety +6

    Had to process a 120k line csv at work the other day. Awk was a god send

  • @OpusFocus1968
    @OpusFocus1968 Před rokem +5

    Thank you Derek I appreciate the time and effort you put into making these videos. You help us "middle users" take things up a notch. Middle as in we are no longer beginners but won't ever be sysadmins. We do however want more out of their Linux system.

  • @skirnir393
    @skirnir393 Před 2 lety +3

    Good introduction to awk. Back in 2013 i had to parse huge log files that had no field separator, even worst each line could be completely different depending on certain conditions. Awk saved my life.

  • @pnavais
    @pnavais Před 2 lety +2

    Straight to the point & excellent as always. Keep up the good work DT ! 👏

  • @rochakgupta6116
    @rochakgupta6116 Před rokem +1

    DT, you are amazing man. Yours are the only videos I have been watching on a daily basis. Thanks for sharing all the knowledge!

  • @wowgingermobile2123
    @wowgingermobile2123 Před 10 měsíci

    This is truly amazing, hope to have another new Awk video in the furure!

  • @zainjadoon759
    @zainjadoon759 Před 2 lety +2

    I have been putting this off for a long time thanks for encouraging me to finally learn it.

  • @mrdanymotion1903
    @mrdanymotion1903 Před 2 lety +1

    Hell yeah!!! AWK arrived at the right time!! Thank you Derek!

  • @jeffg4686
    @jeffg4686 Před 2 lety +1

    Thanks for the share. I used use text editors like Textpad to do these things with regex, but this is so much better since not just find/replace, but perform operations on each result, and being able to easy have in a shell pipeline of commands. Always too lazy to learn it for some reason, but now I'm motivated.

  • @h0ck3y66
    @h0ck3y66 Před měsícem

    I love you man, you're the only one who was able to explain awk in a simple yet effective way. I finally understand how awk works!

  • @bradleyeverson697
    @bradleyeverson697 Před 2 lety +1

    Hey DT. Great review of the power of "awk". You cover all the basic functions for a new user. I use "awk" in a shell script to sort through my datalog's results that i need. Then dump it to a csv file.

  • @fargoflagrant7796
    @fargoflagrant7796 Před 2 lety +3

    This is really helpful and practical, thank you DT!

  • @name1355_0ne
    @name1355_0ne Před 2 lety

    Very nice introduction to awk features. Thanks for sharing this useful knowledge!

  • @dragonsage6909
    @dragonsage6909 Před rokem +2

    That was some awesome awk-fu bro, thank you!

  • @TheBlueThird
    @TheBlueThird Před 2 lety +2

    DT, this is an excellent video! Thanks!

  • @rickbhattacharya2334
    @rickbhattacharya2334 Před 2 lety +3

    Thank you professor DT for the lecture .

  • @zeppelinmexicano
    @zeppelinmexicano Před 2 měsíci

    This is a great review of some practical usages.

  • @baruchben-david4196
    @baruchben-david4196 Před rokem +1

    Thanks for this video. It helps me understand how to use awk better.

  • @KeepItTechie
    @KeepItTechie Před 2 lety +28

    Great tutorial DT! AWK is very powerful!

  • @jacksystems
    @jacksystems Před 2 lety +1

    Very useful info DT! I only knew how to print columns in awk.

  • @balochcode
    @balochcode Před 11 měsíci

    Excellent presentation!! to the point and straight forward! great job!

  • @psadi_
    @psadi_ Před 2 lety +121

    I bet someone is already rewriting awk in rust for the memes.

    • @alessandroferrari4699
      @alessandroferrari4699 Před 2 lety +9

      you mean for speed and safety? /s

    • @rishirajsaikia1323
      @rishirajsaikia1323 Před 2 lety +5

      @@alessandroferrari4699 people use rust because it's fast and easier to solve errors and even rivals c in speed while being easier.

    • @TheSulross
      @TheSulross Před 2 lety +21

      yes because obviously all these 40 year old Unix tools are buggy and broken after thousands upon thousands of users applying them daily over many decades

    • @cgme7076
      @cgme7076 Před 2 lety +1

      @@TheSulross exactly 😂😂

  • @ourallabrador4023
    @ourallabrador4023 Před rokem +6

    I have been using linux for years living on a few commands. I had only a faint knowledge of the command/programs such as awk or sed. Mainly because I had no ideas of their capabilities and use cases. Now I can see how useful they can be. I usually recommend your channel to my PhD students and observed a real improvement in their computer skills. IMO your channel is vital for linux wannabe and "familiar but not expert" users. So thank for your work.

  • @al1234
    @al1234 Před 2 lety +3

    This is the kind of stuff I love to watch

  • @addaline9645
    @addaline9645 Před rokem

    I learned so much more here in 20 mins then I did in my last two classes about this

  • @Jerry-fy2gc
    @Jerry-fy2gc Před 2 lety +1

    Thanks buddy for such clear explanations. Now I'm comfortable to start write some crazy scripts.

  • @vn1384
    @vn1384 Před rokem +1

    This is a great video on AWk..thanks

  • @eritert
    @eritert Před 2 lety +2

    Awk is awesome, great vid I learned a lot

  • @Lucas-md8gg
    @Lucas-md8gg Před 2 lety +1

    My payment will be available in 2 weeks, then I'll be a patreon. Your content is amazing.

  • @Desi-qw9fc
    @Desi-qw9fc Před rokem +2

    Great video. An accessibility note: Your console’s active line is at the very bottom of the screen, which is where CZcams on Smart TVs puts the subtitles, so the subs block the thing you’re typing. It would be better if your terminal was sized so that the bottom 10-20% of the screen isn’t used.

  • @kirk0831
    @kirk0831 Před 2 lety

    Thank you for doing this video. Very helpful.

  • @Hexalyse
    @Hexalyse Před 2 lety +26

    awk is awesome, but if you just want the number of lines, using wc is less characters to type :)

    • @TheSulross
      @TheSulross Před 2 lety +1

      yeah, that was one example that did not resonate at all because wc will also provide totals when applied against multiple files - much less to type to just use wc

    • @egor.okhterov
      @egor.okhterov Před 2 lety +3

      The point is to show what you can do with awk =)

  • @drzmuhammed
    @drzmuhammed Před rokem

    This was helpful, thank you 😊

  • @davidgomez79
    @davidgomez79 Před 2 lety +1

    Great vid DT!

  • @elad3958
    @elad3958 Před rokem +1

    Great tutorial. I learned more in 20 mins w/ awk then in 7 years in IT.

    • @datturns9947
      @datturns9947 Před rokem

      What did you do then in 7 years of IT? :))

  • @abarocio80
    @abarocio80 Před 2 lety +49

    Good video. Some of these, I didn't knew.
    An error in the video: it wasn't the "square root", but just the "square", or "power of two". The square root of 4 is 2, the square root of 9 is 3, the square root of 25 is 5, and so on.

    • @christopherdavies7403
      @christopherdavies7403 Před 2 lety +15

      i came to the comments expecting every comment to be this. I am highly disappointed in the YT comments shit posting today.

    • @gordonbai5320
      @gordonbai5320 Před 2 lety +2

      @@christopherdavies7403 And this guy says 'I didn't knew', grammar mistake.

    • @charlieoocharlie9466
      @charlieoocharlie9466 Před 2 lety

      @@gordonbai5320 ok boomer

    • @weege5.45
      @weege5.45 Před rokem

      @@charlieoocharlie9466
      FLAME WAR!
      And you live in your mother's basement.

  • @milo_andrs
    @milo_andrs Před 2 lety +2

    Nice, thank you. I am beginning my journey on bash and this is awesome.

  • @umop3plsdn
    @umop3plsdn Před 2 lety +2

    love both Sed and Awk

  • @keebler6591
    @keebler6591 Před 2 lety +4

    Great video DT! Thanks for the awesome awk tutorial
    Except:
    s/square\ root/square 😀

  • @amanchauhan4356
    @amanchauhan4356 Před rokem

    This was helpful…. Thanks to u and ur team

  • @ismoiljonabdumajidov9260

    i really appreciate your effort , thank you for the great lesson MAESTRO .

  • @UkranianStallion
    @UkranianStallion Před 2 lety +3

    Sir, your a wizard with awk, i only knew half of this 😂

  • @fabrice9848
    @fabrice9848 Před rokem +1

    The simple fact that fish is your default shell deserves a like and a subscription.

  • @VexisMorlock
    @VexisMorlock Před 2 lety +5

    Great TUT. I ran into an issue because I don't use uniq and sort often enough; uniq doesn't work if dupes are not adjacent so you need to sort first.

  • @calvinproject
    @calvinproject Před 2 lety +1

    Amazing! Basically I can programming using awk. Thanks

    • @DistroTube
      @DistroTube  Před 2 lety +1

      Yea, you can actually use "awk" as a scripting language. Might have been useful in past decades. But now, I'm not sure why anyone would script with awk when things like bash and python exist.

    • @raushonmunni2633
      @raushonmunni2633 Před 2 lety

      @@DistroTube maybe awk faster than python and more specific programming language bash or posix shell

  • @davidruedeman9990
    @davidruedeman9990 Před 2 lety +1

    Learned more about awk in 20 minutes than in the previous 40 years

  • @anthienvo
    @anthienvo Před 2 lety +1

    Heaviest 20 minutes in my life. Worth it

  • @Soupie62
    @Soupie62 Před 2 lety +2

    A little bit of Awk can be useful.
    My standard example: I have a list of shares I track. The website I use lets me download data, but holds more data (open, close, max, min,volume ) than I want.
    Awk is perfect for filtering a single column (close values).

  • @ToallpointsWest
    @ToallpointsWest Před rokem

    USEFUL!! Thank you!

  • @c434rdd410
    @c434rdd410 Před 2 lety

    thanks awk command that help me a lot in my project after watching this video ^_^

  • @elderberry-hamster
    @elderberry-hamster Před 2 lety +1

    Great tutorial! I do prefer the WTF command. It covers all my confusion when trying to navigate the command line. 😜

  • @korleone72
    @korleone72 Před rokem

    that is a very cool podcast, very useful. thank you

  • @chang112x
    @chang112x Před 2 lety

    Very Powerfull. Thx for the video.

  • @sureshsurendran737
    @sureshsurendran737 Před 10 měsíci

    Awsome presentation 👍

  • @JoshBenore
    @JoshBenore Před 2 lety +4

    I have always had trouble with awk because of all the syntax involved, this helped sooo much.
    When you pressed enter on the square root part then said that the output was correct, this is the task list I had to perform to get back on track:
    1. Facepalm
    2. Pull fire alarm
    3. Crying session
    4. Shower with clothes on
    5. Call Mom
    6. Eat some sweets
    7. Finish the video

  • @ghdbdeeeeeaqqq
    @ghdbdeeeeeaqqq Před 2 lety

    Excellent, thank you very much!

  • @user-ug4gy4bn1p
    @user-ug4gy4bn1p Před 6 měsíci

    Great video, helpful comments and even better resourceful and corrective people in the comments

  • @rogernevez5187
    @rogernevez5187 Před 2 lety +1

    Awk ... very meaningful name !!!
    Looks like an assembly instruction.

  • @bitti1975
    @bitti1975 Před 2 lety

    The problem with awk is that most people know it but all seem to think its whole purpose is just to extract columns. This Video gives many practical example that it's so much more.

  • @christianalvarez8606
    @christianalvarez8606 Před 2 lety +1

    Your audio sound 1000x better then before

  • @dumitrus.6925
    @dumitrus.6925 Před 2 lety +1

    I enjoyed your presentation on awk and I subscribed to this channel. I have a question: Can awk to the following job -- send the first line of a file1, delimited by default space, to another file2, file2 that would take its name from the first few fields of the line 1 just transferred from the file1? Thank you

  • @Winnetou17
    @Winnetou17 Před 2 lety +5

    I think a very good example of how good & useful is awk is the example of a log like the apache access log (in the default format) and properly filter the requests that responded with a 400 or 503 response, given that you can find 400 and 503 in the request address, or in the size or the time it took to complete. Also to filter all requests that are longer than a second for example and many other things like that. It's basically Excel powers in CLI over column-structured data/files (which are common in commands outputs or log files)

  • @trido3815
    @trido3815 Před 2 lety

    Thanks for sharing.

  • @senthil_the_analyst
    @senthil_the_analyst Před 2 lety +1

    Quality content 💯

  • @mehdimahdavi6619
    @mehdimahdavi6619 Před rokem

    Hi, thx for ur great videos reagarding Linux! I have a question: r u still using trackballs?

  • @Learnerofthings
    @Learnerofthings Před 2 lety

    Great channel, great information.

  • @seansretroverse9082
    @seansretroverse9082 Před 2 lety

    Nice Luther insult at 8:20! I for real laughed out loud on that one. I'm surprised no one called that out in another comment...😁

  • @Merigold83
    @Merigold83 Před 2 lety +1

    Your example for the line count can be reproduced with the command "wc -l /foo/bar/file_a /foo/bar/file_b"

  • @hendrikbonthuys9190
    @hendrikbonthuys9190 Před 2 lety

    Useful video thanks 🙏

  • @guilherme5094
    @guilherme5094 Před 2 lety

    Thanks DT.

  • @SeekerOfSouls
    @SeekerOfSouls Před 2 lety

    Awesome... good to know how versitile awk is.

  • @TheJacov
    @TheJacov Před 2 lety +1

    Yup, awk is cool. Just as an aside that was squares, not square roots. For square roosts you would need something like (n^(1/2)). AWK does have ^ which is raise to the power function. Raising a number to a fractional power is taking the root.

  • @jacksongodsey
    @jacksongodsey Před 2 lety +1

    This couldn't have come at a better time! I was seeing this command everyone in people's dwm configs and had no clue what it is.

  • @SuperCapello1
    @SuperCapello1 Před 2 lety

    Thank you!

  • @magefreak9356
    @magefreak9356 Před 2 lety

    Always great content DT! Is there a way around the case where the field separator is inside the entries? Like the ps -ef command output has spaces inside the content as well as spaces being the field separator.

    • @locatemarbles
      @locatemarbles Před 2 lety

      I'm sure there is an awky way to do it, but in this case i would be lazy and choose sed.

  • @braelinmichelus
    @braelinmichelus Před 2 lety +1

    A couple months ago I wrote a little shell script to
    gather system information such as
    CPU model, memory, computer model, shell, WM
    (using lscpu, dmidecode, etc)
    and I had to learn a little bit of Awk, Sed, and Grep
    to clean it up and make it look pretty.
    This video would have came
    in handy back then, instead of spending 30 minutes
    reading StackExchange articles on them!

  • @unknownpng650
    @unknownpng650 Před rokem

    yayy lets goo with awk

  • @AWriterWandering
    @AWriterWandering Před měsícem

    I really need to push myself to use awk more. A lot of this can be done by just combining grep, sed, and cut, but it’s kinda nice having it in one process.

  • @vkg2958
    @vkg2958 Před 2 lety

    Good Morning Sir,
    I just wanted to know which Distro and terminal you're using here?.. it's so dope! 🔥 Also that fun message after entering wrong syntax LOL that's where I lost it..

  • @AkashAgrawal03
    @AkashAgrawal03 Před 2 lety +1

    Thanks for making this video! I've tried a couple of times to add AWK to my arsenal, but gave up halfway. This has inspired me to give it a more serious go. I'm generally pretty comfortable with grep and sed but looks like I can make this work for replacing those two for many use cases.

  • @rolcarislew7761
    @rolcarislew7761 Před 2 lety +1

    Yup, it's a complete language, as it is taught in CS degree courses (when taught). However this guy, otherwise, is a far more interesting teacher. Thanks, DT! This app/language confusion here is, like with Python, there is the language, AND there is ERIC, a free IDE that comes with Python. ERIC executes Python, but it's NOT Python. The AWK IDE is more invisible, but there. You can write independently, then execute.

  • @koustav2008
    @koustav2008 Před 2 lety

    EXCELLENT !!!

  • @AnonymousAnonymous-xx3zq

    Fully agree, sir

  • @ivans3806
    @ivans3806 Před 2 lety +7

    Please do jq tutorial next: it's so awesome to manipulate json data, combined with curl it's very powerful for working with REST apis

    • @ghodawalamoamanzahirabbas8996
      @ghodawalamoamanzahirabbas8996 Před rokem

      Is jq a GNU utility?

    • @ivans3806
      @ivans3806 Před rokem

      @@ghodawalamoamanzahirabbas8996 it isn't (according to short duckduckgo search :) ) - but it's amazing nonetheless!

  • @jazzyniko
    @jazzyniko Před 5 měsíci

    What the heck?
    That awk thing is amazing!!!!!!!!!!

  • @aldeezy1
    @aldeezy1 Před 2 lety +1

    small suggestion, bring the bottom of your terminal window up a bit so the youtube progress bar doesn't cover up the command you're entering when the video is paused. Thank you for making this!

    • @warhawk_yt
      @warhawk_yt Před 2 lety

      I know in most window managers you can change the size of a window from left or right but not on the top or bottom at least from what I have seen unless you are in floating mode than you can change it to any size. Most of the space around each window is configured hard coded in your window manager config. You could change it but than would have to change it back after a video.

    • @aldeezy1
      @aldeezy1 Před 2 lety

      @@warhawk_yt clearly he just needs to increase the edge padding to something crazy like 48-64 pixels for the [ M A X I M U M R I C E ]

  • @flesz__
    @flesz__ Před rokem

    Thanks! What mic are you using?
    Also 7:40 , you could use awk -F "/" '{print $NF}' /etc/shells for the same result
    Your df command gives output equivalent to df -h , I suppose you configured an alias?