Why Use CAT Or GREP When You Can AWK?

Поділитися
Вставка
  • Опубліковано 8 вер 2024
  • Enough of the bloat! You don't need to use cat, grep, head, sed, etc. All you need is AWK!
    REFERENCED:
    ► www.gnu.org/so...
    WANT TO SUPPORT THE CHANNEL?
    💰 Patreon: / distrotube
    💳 Paypal: www.paypal.com...
    🛍️ Amazon: amzn.to/2RotFFi
    👕 Teespring: teespring.com/...
    SOCIAL PLATFORMS:
    🗨️ Mastodon: mastodon.techn...
    💬 IRC: irc://freenode #distrotube
    👫 Reddit: / distrotube
    DT ON THE WEB:
    🕸️ Website: distrotube.com/
    🌐 Gopherhole: gopher://distro.tube
    📁 GitLab: gitlab.com/dwt1
    FREE AND OPEN SOURCE SOFTWARE THAT I USE:
    📽️ Open Broadcaster Software: obsproject.com/
    🎬 Kdenlive: kdenlive.org
    🎨 GIMP: www.gimp.org/
    🔊 Audacity: www.audacityte...
    💻 VirtualBox: www.virtualbox...
    Your support is very much appreciated. Thanks, guys!

КОМЕНТАРІ • 326

  • @maximilian200057
    @maximilian200057 4 роки тому +191

    Just one day after Luke Smith's video.
    ua-cam.com/video/82NBMvx6vFY/v-deo.html

    • @eritert
      @eritert 4 роки тому +31

      Things are heating up. Next: Why awk sucks

    • @90hijacked
      @90hijacked 4 роки тому +11

      Only SIX YEARS after Conner McDaniel's awesome SED series >:P

    • @mikewayland2576
      @mikewayland2576 4 роки тому +16

      @@eritert Next on chris titus... Why Awk is the Devil and Why So Many No Longer Use It :P

    • @agenttank
      @agenttank 4 роки тому +6

      who's the noob now? very awkward
      ;)

    • @bendover4728
      @bendover4728 4 роки тому +4

      @@eritert Why awk is bloated.

  • @OliNorwell
    @OliNorwell 4 роки тому +172

    2:54 - why bother with cat when you can awk and make the command 8-10 characters longer? I get that awk is an interesting program, but this is absurd. Come on DT, these videos are great but this is silly.

    • @bendover4728
      @bendover4728 4 роки тому +7

      He would use "sed" instead..

    • @nobytes2
      @nobytes2 4 роки тому +12

      Yeah people don't use akw because a lot longer commands. Even the first users of unix like Brian still use cat, is perfectly fine. Also people use grep because is shorter. So cat and grep are the pure essence of Linux programs in the 70s be great at one thing. Awk has its purpose but it isn't to replace grep.

    • @nobytes2
      @nobytes2 4 роки тому +7

      Here's a video of Brian the creator of AWK which says grep is his favorite command lmao ua-cam.com/video/O9upVbGSBFo/v-deo.html

    • @ArdieMejia83
      @ArdieMejia83 3 роки тому

      Couldnt disagree more.

    • @manuarteteco6153
      @manuarteteco6153 3 роки тому

      @@ArdieMejia83 care to elaborate? Why would you still use awk when cat is way shorter and easier to type?

  • @dkosmari
    @dkosmari 4 роки тому +122

    My suggestion is to not waste time showing how a tool can awkwardly emulate another, but what it can do better. Splitting fields is one of the most common uses for awk.

    • @_yuri
      @_yuri 4 роки тому +21

      you mean awk wardly dab

    • @__-wv1my
      @__-wv1my 4 роки тому +21

      Exactly what I was thinking. "Why use "head" when you can type out this much more verbose syntax to accomplish the same thing?" hmm

    • @humm535
      @humm535 4 роки тому +3

      And splitting fields with awk is not _awk_ wardly (haha) emulating other tools? Like ... _cut_ for cutting fields?

    • @igwadaa3422
      @igwadaa3422 2 роки тому +1

      Well i think what's he's highlighting here is that, maybe those tools could share more of they're functionalities in a UNIX mentality, instead of having their own ways of doing some same things. awk, sed and grep could use cat binary and have it in dependency to get text from file. It would make more sense.
      But i think that's kinda the goal of busybox

    • @discomallard69
      @discomallard69 Рік тому

      why carry around a hamer when you can hammer things with your shoe?

  • @Trigex
    @Trigex 4 роки тому +42

    To be fair, Luke specifically was talking about piping cat into grep for standard grep uses, he never proposed it as a replacement for cat in it's whole. Interesting video though!

  • @softhax
    @softhax 4 роки тому +50

    DistroTube vs Luke Smith : Civil War 😂😂

    • @bendover4728
      @bendover4728 4 роки тому +4

      Than-O.S. is coming! LoL

    • @meyimagalot9497
      @meyimagalot9497 4 роки тому +3

      No it's not. Unaboomer while immensely popular, doesnt rely on YT - he is a community builder (without probably realizing it) around i3, as he gets real life problems and shows the solutions. He's a freaking eye opener. He's not a news outlet and doesnt search for topic to cover - he discover something useful, teaches himself, improving a toolkit and shares with us.
      He shows you realtime what you can do with it from the point of view of regular (yeah, right...) staff of the university of Arizona (or in whichever hole is he know).
      Picking up on him without understanding his point (which is 20-30%% performance boost, 6 minutes instead of 9 for longer scripts) is childish and as much pathetic as calling him "another creator"

  • @mitchelvalentino1569
    @mitchelvalentino1569 4 роки тому +44

    3D terminal games have been written in Awk. It’s that powerful.

    • @DistroTube
      @DistroTube  4 роки тому +19

      Tetris games have been written in awk. True story.

    • @msdosm4nfred
      @msdosm4nfred 4 роки тому +1

      @@DistroTube I like Tetris, since it was released in europe, because I'm born in the former GDR.

    • @urugulu1656
      @urugulu1656 4 роки тому +3

      @@msdosm4nfred are you sure this is the right channel for you? just going by the name.

    • @pineiden
      @pineiden 4 роки тому

      Really? Where what?

    • @raushonmunni2633
      @raushonmunni2633 3 роки тому +1

      @@urugulu1656 MS-DOS is now open source, atleast 1.25 and 2.0. So isn't it technically the best non-POSIX os now. repo link github.com/microsoft/MS-DOS

  • @vanderfleet-martin
    @vanderfleet-martin 4 роки тому +9

    I believe that the Unix philosophy is small single purpose tools that do one thing well. That is why you would use grep instead of awk, not to mention that the grep command line was very much simpler and easier to remember than the awk equivalent. That said, this was a very interesting video on how the same things can be accomplished with different tools.

  • @mitchelvalentino1569
    @mitchelvalentino1569 4 роки тому +21

    This video is spot on. Awk is seriously underutilized. One of my favorite commands.

    • @meyimagalot9497
      @meyimagalot9497 4 роки тому +11

      If you use awk for this, you shouldnt be allowed anywhere near scripting in any production environment :D

    • @gappergob6169
      @gappergob6169 4 роки тому +4

      @@meyimagalot9497 lol

    • @humm535
      @humm535 4 роки тому +6

      awk is underutilized, _as a scripting language_ .
      It’s not very useful as a command, but as a scripting language for all sorts of text manipulation. Other stuff often done using awk as a command have their own commands (cutting fields with cut, _grepping eith grep_, replacing characters with tr, simple stream operations with sed, ...). awk is a scripting language!

    • @mitchelvalentino1569
      @mitchelvalentino1569 4 роки тому +3

      Humm semantics and pedantics, eh? I enter the awk command and use the awk scripting language daily :)

    • @humm535
      @humm535 4 роки тому +1

      @@mitchelvalentino1569 Pff. awk is for longer scripts (although not getting _too_ long ... usally ~50 loc.)

  • @BrenoSilveira94
    @BrenoSilveira94 3 роки тому +6

    "Why use awk and sed if you can use Perl?"
    Just kidding, Perl is awesome.

    • @alexxx4434
      @alexxx4434 3 роки тому

      Why use Perl when you can use Node.js?

    • @BrenoSilveira94
      @BrenoSilveira94 3 роки тому

      @@alexxx4434 Because js it is a soydev language.

    • @alexxx4434
      @alexxx4434 3 роки тому +1

      You though I was serious?

    • @BrenoSilveira94
      @BrenoSilveira94 3 роки тому

      @@alexxx4434 Yes, sorry. I wooshed my self.

  • @garysalisbury4117
    @garysalisbury4117 4 роки тому +16

    All depends on the task ... and the size of the data-set and the time allowed to do it !!

  • @AnzanHoshinRoshi
    @AnzanHoshinRoshi 4 роки тому +18

    Thank you, Derek. "Bloat" is bloat. Use "blo" instead.

    • @unfa00
      @unfa00 4 роки тому +2

      Gnu/Bloat

  • @bfrd9k
    @bfrd9k 4 роки тому +3

    Not piping from cat into grep makes sense. Using awk instead of quicker alternatives does not. grep, head, tail, and sed, are shorter and easier to type and give the same results. I bet they complete quicker as well.

  • @ChrisTitusTech
    @ChrisTitusTech 4 роки тому +2

    *grabs popcorn* I am enjoying seeing Luke and DT go back and forth with these commands. It's like watching an awesome game of chess.

  • @0x007A
    @0x007A 4 роки тому +10

    For beginners 'bc', 'cat', 'curl', 'head', 'grep', 'sed', 'tail', 'wc', and 'wget' are easier to learn for text retrieval and processing; the subprocess operator $() comes in handy too. In contrast, 'awk' is a text-processing utility with a built-in programming language. Those 5 utilities plus 'gnuplot' are sufficient for data analysis and much of data science. If programming language constructs such as variables, loops, and user-defined functions are needed, a standard *nix shell like 'bash' provides these features. By the way, I use all of these utilities and sometimes only the full capabilities of ''awk' on a daily basis to perform all stages of the data science workflow, including machine learning. Whether I choose to go awk-less depends on the project. Okay, I am sadistic. By the way, I use Python and R too but when introducing data analysis or the stages of the data science workflow up to exploratory data analysis. The 'bc', 'cat', 'curl', 'head', 'grep', 'sed', 'tail', 'wc', and 'wget' utilities allow for an interactive, step-wise refinement approach known as REPL without the cognitive overhead of programming language constructs.

  • @marvinjohnson6717
    @marvinjohnson6717 4 роки тому +4

    The cat replacement can be shortened to awk 1 new.sh. I do this instead of cat when I think I will want to perform an action on the file using awk after I view the contents. Now I can recall the last command and simply replace the 1 with the AWK program.

  • @bigfootisjustreallyshy
    @bigfootisjustreallyshy 4 роки тому +15

    This was actually hilarious. Thanks DT

  • @tealc6218
    @tealc6218 4 роки тому +9

    Enough of the bloat you old goat.
    You don't need Cat or exfat.... a head or sed even if the font is in red.
    Don't use grep, or WEP and especially don't use zipgrep.
    In the terminal or youtube as you gawk, while you listen to DT talk
    He says all you need is AWK.
    -----Dr. Suess

  • @strielnikovmaxim8923
    @strielnikovmaxim8923 4 роки тому +8

    Also great way to view firtst few lines using awk.
    awk ''FNR

  • @shushens
    @shushens 4 роки тому +4

    As an awk lover, this video put a smirk on my face. But seriously, awk really shines when manipulating data in a limited number of potential sources. In real life scenarios, searching through large git/mercurial repos, where there are thousands of source files and a lot more build files, awk is not really your friend. All searching operations will be much much slower than grep. Grep will also be much slower than SilverSearcher or RipGrep, but those tools are not a part of any Gnu/Linux distribution.
    But you are absolutely on point about replacing sed with awk. Even when awk syntax looks longer, it is more meaningful and readable.

  • @waldmatias
    @waldmatias 3 роки тому +5

    Great video... but you answered yourself really. The simplest solution (or more readable) is usually the best one... so which do you prefer to use in a script?
    This: head file.sh
    Or this: awk '(NR>=0 && NR ... etc etc about 20 more characters... ' file.sh?
    Which would be more readable and maintainable while also allowing fellow programmers looking at your code to 'get it' quickly?

  • @altaccount8749
    @altaccount8749 4 роки тому +2

    Some people use TurboTax to file their taxes. I file them with AWK.

  • @typecasto
    @typecasto 3 роки тому +2

    1:40 "why bother with grep? grep is sort of a neat program, but it really only does one thing"
    have you heard of the unix philosophy?

  • @user-ic7cj8lq9z
    @user-ic7cj8lq9z 4 роки тому +4

    Yea I think I recall seing this video recently of some boomer talking about using sed instead of cat.

  • @fanshaw
    @fanshaw 6 місяців тому

    The reason we use cat at the beginning is that it moves the file being referenced to the start of the line before any processing commands. Otherwise you've got grep followed by a random pattern match, then the file you're processing, often followed by a long sequence of other things. It's easier to read and conceptualise when you have "take file X | search for content y | ..." especially if you're chaining many commands together and later you have more greps or sorts and you switch the mode of their use from including a filename to taking stdin. It makes the $1 stick out and easy to understand rather than burying it somewhere down the commandline.

  • @dvancamp
    @dvancamp 4 роки тому +3

    Why use grep when you can just print the file out on a dot matrix printer and use white-out on all the lines you don’t want to see?

  • @Khyree_Holmes
    @Khyree_Holmes 4 роки тому +6

    "This got AWKward."

  • @davidgomez79
    @davidgomez79 4 роки тому +13

    awk is awesome, I use it to update pip installs
    pip list --outdated | awk 'NR >2 { print $1}' | xargs pip install --upgrade

    • @DistroTube
      @DistroTube  4 роки тому +3

      Nice!

    • @davidgomez79
      @davidgomez79 4 роки тому +1

      @@DistroTube forgot xargs, but, edited the post

    • @davidgomez79
      @davidgomez79 4 роки тому +4

      @Peter Andrijeczko for using awk? No, I was sharing an example for newcomers. Its aholes like you who scare people away from linux man. How in the F, am I going to look for congratulations for simple line of awk, when I've written emulators in ASM for both 6805 and 6502. Go bug someone else if you're the bored man.

    • @davidgomez79
      @davidgomez79 4 роки тому

      @Peter Andrijeczko this isn't a penis measuring contest, I'm just saying, you came off as an ahole and you know you did.
      I'm sure you're way more capable than me but honestly, years don't equate to ability. I found and exploited a security whole in nagravision cards used by popular tv providers. A loop counter was off by one and overwrote the counter itself in ram. The loop itself was decrypting memory with IDEA cipher with a key of zero for a few loops then they got over written with a constant key. I had to encrypt my payload with 2 keys and then used another command to cause a jump to the payload in ram. I've never worked with linux as an employee and I'm self taught but. People will have their strengths and weaknesses all over the place. Like I said this isn't a pecker measuring contest.

    • @davidgomez79
      @davidgomez79 4 роки тому +1

      @Peter Andrijeczko this why i wrote emulators for both the 6805 and 6502, these cards where using these same architectures depending on the rom version. for the 2nd part of the exploit I wrote code in C++ so i could brute force a set of bytes that would give me a jump to my payload since what was being overwritten in ram was psuedo-random. I need a jump to anywhere from $0080 to $00D0 in ram. but yeah im not pro or expert.. I learn as I go and when it comes to linux I'm still a beginner. Hell I stick to debian or ubuntu for that very reason.

  • @Ultrajamz
    @Ultrajamz 4 роки тому +26

    Only way Luke can redeem himself is if he does a NixOS series

  • @CrobsAdventures
    @CrobsAdventures 4 роки тому +4

    This video is such a flex that he is literally flexing in the thumbnail, love it!

  • @CarloPiana
    @CarloPiana 4 роки тому +14

    Using awk for everything is surely doable, but sounds like a gimmick to my ear. Interesting, though.

    • @Clobercow1
      @Clobercow1 4 роки тому +4

      I think that's the joke. There is nothing wrong with using cat or grep if that's what you're used to doing.

  • @TheSulross
    @TheSulross 3 роки тому +1

    At some point these classic Unix tools just become verbs for what we want to do - when we just want to dump files as is, or combine several files into one, we achieve that via the verb of 'cat'. When we want to scrape things per line out of a file, we 'grep' it. If we want to scrape, filter/transform a file, we 'awk' it. Even if there were one uber tool that could do all these things, I'd have to create aliases for 'cat', 'grep', 'awk' so those verbs would still be there

  • @lunge1
    @lunge1 4 роки тому +14

    I see where this is going.

    • @humm535
      @humm535 4 роки тому

      _Glenda’s so cuuute!_

  • @seanoh432
    @seanoh432 4 роки тому +1

    using awk it feels like im using dvorak keyboard because of those special letters, eapecially when i need to finish jobs faster, i only use awk for missing features like print. time is gold.

  • @sasakanjuh7660
    @sasakanjuh7660 4 роки тому +2

    As for head replacement, you can simplify command to "awk '{ if(NR < 11) print; else exit }' new.sh" :)

    • @sasakanjuh7660
      @sasakanjuh7660 4 роки тому

      @@bigpod I meant simplification of command he provided as replacement for head. But, in general, it is quite simple command, there's really not much to it :)

    • @sasakanjuh7660
      @sasakanjuh7660 4 роки тому

      @@bigpod Sure it is, can't argue with that, but I think that was not a point of the video :)

  • @garysalisbury4117
    @garysalisbury4117 4 роки тому +4

    echo "cares one No" | cat | cat | awk '{ print $3, $2, $1 }'

    • @stanlo45
      @stanlo45 4 роки тому +1

      Ha ha ha.... awkward ;-)

  • @rashidxd
    @rashidxd Місяць тому

    For replacing head, you only need: "awk 'NR

  • @dmiracle74
    @dmiracle74 4 роки тому +1

    Awk is like using a sledgehammer to drive in a nail. LoL. I will continue to use cat and grep.

  • @spirkinator
    @spirkinator 4 роки тому +1

    Awk is 671KB, plus 34K for the links from /usr/bin/awk -> /usr/bin/gawk. Cat, grep, sed, head, and tail are 475KB combined. Awk is teh B|0@t!

  • @kungfumachinist
    @kungfumachinist 4 роки тому +1

    Blargh! Captain Pedantic here... it's not "case insensitive" it's "case indifferent". It's the same difference as "uninterested" and "disinterested".

  • @mkd1113
    @mkd1113 4 роки тому +73

    why say 'content creator'? Just name Luke Smith. good video apart from that dt

    • @meyimagalot9497
      @meyimagalot9497 4 роки тому +1

      YOu know, not to shout out the competition... OMG how low-key, jealous and petty it is.... I cant help it, but to me tells a lot about the character.

    • @ariathyf144
      @ariathyf144 4 роки тому +3

      Felt almost insulting tbh.
      Chill Luke is giving him ideas for new content and he's not bothered to pay respect or acknoledge a gnu user fellow.

  • @DJ_Cthulhu
    @DJ_Cthulhu 4 роки тому +19

    BEGIN { print "Luke Smith" }
    😉

    • @90hijacked
      @90hijacked 4 роки тому +1

      sed "1 i Luke Smith"

  • @AWriterWandering
    @AWriterWandering 5 місяців тому

    The one caveat with replacing grep with awk is that it doesn’t support extended or Perl-like regex the way modern GNU grep does.

  • @moreirajesse
    @moreirajesse Рік тому +1

    I didn't know the "tolower()" parameter in the awk command. I learned it with you. Thanks man. Greetings from Brazil.

  • @vitiok78
    @vitiok78 4 роки тому +5

    I think we need to include all that stuff into systemd )))

  • @garysalisbury4117
    @garysalisbury4117 4 роки тому +1

    echo "When The Band goes Filing in" | awk '{print substr($1,1,1)substr($2,1,1)substr($5,1,1)}'

    • @eNNercY
      @eNNercY 4 роки тому +1

      Is it „wtf“?

    • @garysalisbury4117
      @garysalisbury4117 4 роки тому

      @@eNNercY Yes :)

    • @garysalisbury4117
      @garysalisbury4117 4 роки тому

      @@eNNercY LOL unix / linix is cool ... but scripting is always quick and dirty ... but will be in no way fast ...
      Arguing between cat and awk is just clickbait !!

  • @adriansrfr
    @adriansrfr 2 роки тому +1

    Grep is still the least cumbersome and most elegant for every day searches. The bloated commands, sed and awk, are better for more specialized cases. Awk is exceptional when it comes to tabular data.

  • @christopheriwen8652
    @christopheriwen8652 4 роки тому +1

    awk '{print $0} (NR==11){exit}' new.sh seems easier to understand and use than what you used for the head example . great video by the way!!

  • @PetterBruland
    @PetterBruland 4 роки тому +2

    It's a tool in the toolbox. It's good to be aware of what the strength of each tool is, and use it in a meaningful way. -Capt. Obvious.

  • @ricardo_valerio
    @ricardo_valerio 3 роки тому +1

    "why use a cap when you can use an umbrella on a sunny day"

  • @freesoftwareextremist8119
    @freesoftwareextremist8119 4 роки тому +1

    I'm using only awk right now for the Advent of Code. It can really do anything.

  • @seanoh432
    @seanoh432 4 роки тому +1

    grep -v apple
    takes 2 seconds max to type letters.
    awk '!/apple/ {print }'
    takes 8 seconds minimum.
    if i use grep 1 week straight,
    awk will take a month.
    when i become 90 years old and medicare bill costs me 100k to extend just a month of life.
    awk? no thx.
    but agree it does things that grep sed cat is missing.

  • @ronobvious1785
    @ronobvious1785 4 роки тому

    Why use cat? Well, cat is a lot easier to type out than awk '{print $0}' . The awk version of case insensitive grep is even worse since you have to explicitly call out each character that might be in both upper and lower case. awk does have some really useful stuff though. I'll have to dig into it further.

  •  4 роки тому +2

    2:54 Typing `awk '{ print $0 }' new.sh` is bloat. Just type `awk // new.sh`

    • @DistroTube
      @DistroTube  4 роки тому +1

      I may need to test this one...
      $ time awk '{print $0}' new.sh
      real 0m0.005s
      user 0m0.002s
      sys 0m0.002s
      $ time awk '//'' new.sh
      real 0m0.003s
      user 0m0.003s
      sys 0m0.000s

    •  4 роки тому +3

      @@DistroTube For full autism, make sure to time how long it takes to type each one. :-D You don't need quotes around // in this particular case.

  • @eduardpertinez4767
    @eduardpertinez4767 4 роки тому

    cat and grep and more and tail are the basis of UNIX systems. Do one thing and do it well. Pipe through the different things you are doing. For me it is easier to remember that cat echoes the file and grep gets the input and filters it in that to remember that grep has all those parameters one of witch is the filename. It sure has ANDs also, yet I use to pipe one grep to another if I am filtering on two conditions. In any case, the examples you give are longer to type and harder to remember that easy cat/grep equivalents.
    Offtopic: After 30 years of using grep for different piped tasks i discovered "grep -r 'someCodeSnippet'" that looks into a folder and shows you all files and file lines that contains a given text. That is soo usefull, I cannot believe I never used it.

  • @johncrunk8038
    @johncrunk8038 4 роки тому +1

    I seldom use cat. Usually "less" or "more" for large files, sometimes with grep. The pipe is the Unix way.

  • @janschmitt
    @janschmitt 4 роки тому +1

    Thanks for the comparison but to me it remains more tedious to use awk before ripgrep, grep...you name it..in most cases. Anyway still learned something new, thanks for that.

  • @Baccarebel2580
    @Baccarebel2580 4 роки тому +1

    Because awk uses more system resources then grep. The reason not to use cat is to minimize the amount of memory needed to be allocated. Only calling grep is more efficient than using awk and also more efficient than evoking cat as well as grep

    •  4 роки тому +3

      Congratulations, you saved yourself 0m0.001s.

    • @Baccarebel2580
      @Baccarebel2580 4 роки тому

      Krešimir BTFO scrub, check out the benchmarks that came out today

    •  4 роки тому

      @@Baccarebel2580 If you're talking about Luke's video, then it shows that you save about 0.001s when using grep like it is intended, instead of awk, which I told you without measuring it. I guess, if you are that pressed for time, it matters, but in normal use nobody can notice the difference.
      Now, nobody is saying you should use awk for everything (DT's video is a bit tongue-in-cheek), but only that you can and that It doesn't really matter in most normal cases. If you cat into grep, no secret police will show up at your door to take you away.

  • @rich13348
    @rich13348 4 роки тому +1

    Why use head when with an extra 40 characters you can use awk to do the same thing. It took him that long to type out the command he jump cut it.

  • @takisharalabidis611
    @takisharalabidis611 3 роки тому +6

    This was an interesting video. However, if I want the head of a file, I will type: head t.txt not the long awk command you suggested. Have you counted how many keystrokes are involved in the awk command? The awk utility is only to be used for complex operations, which other simpler utilities cannot perform. It is not a replacement for all other commands.

  • @JD-im4wu
    @JD-im4wu 4 роки тому +1

    and now for the bigger question... Y use vi when u got awk, sed, grep and the whole 9 yards or bash utils. nano ftw!

  • @TdTSimonBE
    @TdTSimonBE 4 роки тому +10

    Head can be a lot shorter: awk 'NR

  • @CitiesTurnedToDust
    @CitiesTurnedToDust 4 роки тому +5

    When you're working with things like live logs you *must* use cat instead of grep/awk etc to avoid locking the log files you're looking at. Otherwise now you're preventing the system from logging while you work which in some situations (tech support) is unprofessional.
    If you also need to do columnary processing, you can pipe your cat to awk.

    • @MaleSoCal
      @MaleSoCal 3 роки тому

      The last statement fixed the first.

    • @nkpytelzhor
      @nkpytelzhor 2 роки тому

      Could you please elaborate or hand me a reference material? How does awk lock the file?

  • @aristotelispapageorgiou4627
    @aristotelispapageorgiou4627 4 роки тому +4

    awk is great for work with data tables

    • @DistroTube
      @DistroTube  4 роки тому +1

      True, that's really where it shines.

  • @zakhoskins6404
    @zakhoskins6404 4 роки тому +1

    One less dependency............but a few extra characters to invoke. This is the simplest possible example of a tradeoff in programming I can think of.

  • @meyimagalot9497
    @meyimagalot9497 4 роки тому +2

    I think Luke has a point (performance) whereas DistroTube is looking for some topic to talk about

  • @bitelogger
    @bitelogger 4 роки тому +1

    Master this is reveling to me now I'll use AWK for my log and Metadata work.

  • @TheGruselmops
    @TheGruselmops 4 роки тому +3

    It's legit to use cat to just print out a file.

    • @bendover4728
      @bendover4728 4 роки тому

      Cat is bloated. Use "

    • @TheGruselmops
      @TheGruselmops 4 роки тому

      ​@@bendover4728 No, use '>'. Files are bloated.

    • @bendover4728
      @bendover4728 4 роки тому

      @@TheGruselmops LoL! Yo can use 'sudo find / -type f -delete' to get rid of bloating..

    • @TheGruselmops
      @TheGruselmops 4 роки тому

      @@bendover4728 whahaha

  • @farhanaditya2647
    @farhanaditya2647 3 роки тому

    It's like why use _reduce, map, forEach, filter, every, some, includes,_ where you can use _for loop_ for everything.

  • @marcuswest4572
    @marcuswest4572 Рік тому

    6:10 "finds every line that contains 'dir' " : $1 finds every line with 'dir' in the first item

  • @hermask815
    @hermask815 6 місяців тому

    Imagine a carpenter making a video on using solely one specific hammer for all. You’d laugh about that.
    I wouldn’t abandon all other CLI tools.
    Besides the tool to replace them all .. wasn’t that Perl?

  • @unfa00
    @unfa00 4 роки тому +1

    "We can replace head with awk"
    7:37:
    Me: Nope

  • @SebSenseGreen
    @SebSenseGreen 4 роки тому +2

    Did he just declare war?

  • @linuxinside6188
    @linuxinside6188 4 роки тому +7

    War begins .

    • @bendover4728
      @bendover4728 4 роки тому

      100 years from now:
      -- granpa, how the WWIII begun?
      -- you'll see grandkid, all it started with this Linux videos on UA-cam..

  • @f23anone82
    @f23anone82 4 роки тому +1

    Ok, since the "one content-creator" ignored this, maybe you would be interested in making a list of tutorials on core-utils with examples? I think it would be really nice

  • @Harbonium
    @Harbonium 4 роки тому +1

    7:42
    How that did appear? What kind of sorcery you are doing?
    I shall give thee my like Mister Derek Distrotube!

    • @DistroTube
      @DistroTube  4 роки тому +2

      The magic of Kdenlive. I wonder if awk can edit video? Hmm...

  • @auntiecarol
    @auntiecarol 3 роки тому +1

    Pretty soon you'll be browsing the web with awk and curl /s

  • @AkamiChannel
    @AkamiChannel 4 роки тому +1

    awk ‘{print $0}’ file.txt was even more AWKward than cat file.txt | grep “search”

  • @billchatfield3064
    @billchatfield3064 4 роки тому +1

    Why bother with awk when you can use Perl? Perl is easier to understand and can do more. But seriously, awk is cool too. Use whatever tools you prefer, as long as it's not emacs.

    • @stephan8573
      @stephan8573 4 роки тому +2

      Real programmers use butterflies!

  • @GiglioFava
    @GiglioFava 3 роки тому +1

    Awk isn't "almost like its own programming language"; it is one, Turing complete. So... if you're going to stick a snippet of a language between shell pipes, why Awk? Awk was groundbreaking, but with all due respect to A, W, and particularly K, plenty of languages learned from it, and did better. It's neither as succinct as the simple shell commands, nor as powerful (nor even as succinct, often) as a modern language.
    Also, cat | grep is "incorrect"? Really? I mean, jumping around the command line using Emacs chords, or with Vi navigation, is more efficient, but you're not incorrect for tapping the arrow keys.
    Nothing wrong with shell commands; often they're just what you need to bang something out. If you know a scripting language, use it. If you're going to learn one... well, think it over before you pick Awk.
    E.g.:
    cat: ruby -pe '' filename
    grep: ruby -pe 'next unless /#/' filename
    print second field if the first is #: ruby -ane 'puts $F[1] if $F[0] == "#"' filename
    same thing, but pattern matching: ruby -ane 'puts $F[1] if $F[0] =~ /#/' filename
    print each line backward: ruby -pe 'puts $_.reverse' filename
    put a hyphen between every character: ruby -ne 'puts $_.split(//) * "-" filename
    turn uppercase to lowercase, and vice-versa: ruby -ne 'puts $_.swapcase' filename

  • @Zellonous
    @Zellonous 4 роки тому +12

    Something something "awk"ward
    Yeah I know. I couldn't think of anything clever.

  • @bendover4728
    @bendover4728 4 роки тому +1

    Awk is great and is one of the commands I love the most... Only problem being I don't even know how to use it.

    • @MaleSoCal
      @MaleSoCal 3 роки тому

      If you do not use awk yet consider gawk (GNU awk) or nawk (New awk). They are both more powerful.

  • @torben_rr
    @torben_rr 3 роки тому +1

    me, watching videos on awk because my coworker who retired always used awk, and in the end he used awk for everything.
    so I had a really good laugh in the end :D.

  • @Chalisque
    @Chalisque 3 роки тому

    grep -P is not possible with awk; cat is such a common case it deserves its own program (imagine typing awk '{print}' file*.txt every time).
    Likewise, how does one implement grep -n port *.cc in awk?
    (I don't, for example, know how to match the start of a file, necessary to have a per file line number, if multiple files are specified on the command line -- grep -n gives you the filename and line number _in that file_, rather than the line number of all input files concatenated, and this is much more useful than what you can do with awk, before one adds the colour coded output you get from modern grep.)

    • @Chalisque
      @Chalisque 3 роки тому

      Bit more gooling: I'll answer myself with a couple of examples:
      awk '/cout/ {print FILENAME ":" FNR ": " $0}' *.cpp
      awk 'BEGIN {n=0} FNR==1 {n=n+1;print "New File: " FILENAME} END { print n " files" }' *.cpp
      Sure you can do it, but it takes headscratching and more legwork for your poor overworked fingers. I'm someone who, with a specific task in mind, writes a 'scripts.sh' file defining 1-4 char abbreviated commands for the task at hand, just to minimise typing.

  • @jarilo8639
    @jarilo8639 4 роки тому +1

    awk is great but if you are a super nerd use mawk but debian based stuff defaults to mawk when you use awk. so the debian/ubuntu guys are already using it
    adamdrake.com/command-line-tools-can-be-235x-faster-than-your-hadoop-cluster.html

  • @Andrath
    @Andrath 4 роки тому +2

    Why use awk when you can use perl?

  • @logangraham2956
    @logangraham2956 4 роки тому +9

    or just write your own text parser in c/c++ XD XD XD

  • @hellosociety7094
    @hellosociety7094 3 роки тому

    Luke smith: don’t use bash use zsh
    DT: don’t use zsh use fish
    -> 5 years later
    Luke smith: don’t use zsh use fish
    Dt: don’t use fish use dish(a random shell which is not released yet)

  • @scotth8828
    @scotth8828 2 роки тому

    "grep only does one thing" Linux Axiom "do one thing do it well" 🤔

  • @PenguinRevolution
    @PenguinRevolution 4 роки тому +4

    I don't care what I use, as long as I can get the job done ;)

  • @LeonidBraynerMyshkin
    @LeonidBraynerMyshkin 4 роки тому +1

    grep has a builtin -r, or recursive, flag, which is very useful. These days I use "The silver searcher" though.

    • @xthebumpx
      @xthebumpx 4 роки тому

      Check out Ripgrep!

    • @LeonidBraynerMyshkin
      @LeonidBraynerMyshkin 4 роки тому +1

      @@xthebumpx I actually have! I use this vim plugin for searching (vimgrep is so slow) that uses ripgrep. But on the command line I prefer to use ag, even though rg is definitely faster.

  • @bendover4728
    @bendover4728 4 роки тому +6

    % export HE_WHO_MUST_NOT_BE_NAMED="Luke";

  • @wompa70
    @wompa70 4 роки тому

    I hardly ever use cat. I use less most often. The files I deal with are more than just one screen long. I also hardly ever need just one or two key words.

  • @edgar12334
    @edgar12334 4 роки тому +3

    Big brain time: trade awk for perl

  • @soppaism
    @soppaism 2 роки тому

    Everyone should probably use what works for them... I find myself using awk quite often, just because I tend to forget the options/flags for various separate commands (by the time it takes to man, I've already written the awk).

  • @benjaminwagner5440
    @benjaminwagner5440 4 роки тому

    Of cause, why would you do 「head new.sh」 when you can just write 「awk '(NR>=0 && NR

  • @Kralnor
    @Kralnor Місяць тому

    How about using the right tool for the job? Usually that's whatever requires the least code.

  • @daephx
    @daephx 4 роки тому +1

    Why would you present it like this? now awk seems cool but when your commands are far more verbose to get the same functionality and then advertising as a replacement?
    It should be advertised as an alt; depending on your use case, it could be more powerful or even slower then one of the other tools in terms of productivity.

  • @asterix908
    @asterix908 4 роки тому +1

    I'm one of those rare snow flakes that taught myself programming using awk. The programs were some of the fastest running programs you could have. the only issue is awk is so difficult to read and write, I can't even remember how the program I wrote some time ago works. Should've spent that time on python.

    • @MaleSoCal
      @MaleSoCal 3 роки тому

      Sounds like "documenting" at the head of the file sounds in order. Most UNIX/Linus gurus like your self use many languages, for many different reasons time to time.

  • @brianhansen2202
    @brianhansen2202 4 роки тому

    I don’t know this channel, and I will never see it again...

  • @reverseila4363
    @reverseila4363 4 роки тому

    Its sort of like using shovel instead of spoon imo