3 ms·
Awk is fine and dandy but, like wity Sed, I think that it's almost always replaceable with Perl which is way nicer to use, and ubiquitous. Every OS (except Wind
by qalmakka 3y ago
Awk is fine and dandy but, like wity Sed, I think that it's almost always replaceable with Perl which is way nicer to use, and ubiquitous. Every OS (except Windows) I laid my hands on in the last 15 years has had Perl installed in either its default install or pulled in as a dependency almost immediately (a LOT of stuff depends on Perl in any Unix system).
This is, unless you are running on an embedded environment, but in that case you are stuck with something like busybox's Awk which is way more limited than gawk...
- delta_p_delta_x 3y ago> except Windows On Windows, you use PowerShell.
- layer8 3y agoI prefer Cygwin.
- horse_dung 3y agoI just finished writing a “dumb stuff with containers” internal blog which included: C:\> type somefile.txt | docker run --rm -i ubuntu awk ‘something’ > output.txt
- swores 3y agoThey were talking about whether or not the OS comes with Perl by default, not whether it has a CLI at all.
- thesuperbigfrog 3y ago>> On Windows, you use PowerShell. If you use Git for Windows (https://gitforwindows.org/ https://gitforwindows.org/), it includes Perl. Or you could install Strawberry Perl which is made for Windows: https://strawberryperl.com/ https://strawberryperl.com/
- deleted 3y ago[deleted]
- hereonout2 3y agoThe obligatory perl replaced awk decades ago comment. Soon to be followed by the ones saying nobody should be writing shell scripts at all anymore.
- empthought 3y agoPerl is not nicer to use.
- asicsp 3y agoI wouldn't put Perl as easier to use, but it certainly is more powerful and has a vast ecosystem. And it is more portable, since there's no need to worry about GNU/BSD/etc variations. And I wrote a book for Perl one-liners as well (https://learnbyexample.github.io/learn_perl_oneliners/ https://learnbyexample.github.io/learn_perl_oneliners/), which I'm currently revising (like I did for the grep/sed/awk ebooks).
- chasil 3y agoI was actually surprised to find mktime() in Busybox awk. The big thing lacking there are the GAWK networking extensions.
- temp_gnuser 3y agoI have a good story about this: My first time really working with a great scientist, we were taking genetic papers and making them code for improving analysis. I spent two days writing a perl script before I finally got frustrated enough to ask for help. The first question he asked was "Did you email the author(s)?" I said I hadn't and didn't want to bother this seemingly very important scientist. He told me nonsense, that most of them don't mind responding but he warned me to be terse and to the point. I emailed the gentleman and told him what I was doing and my issues, and asked him for some guidance. He sent me back a one line awk-script that did everything all that perl was failing to do! Of course all that proves is I'm horrible at perl, but it was an important moment in my life that showed me that even very smart and important people are still just people, and that just asking is often a great way to learn new things yourself, and that sometimes you just need to step back and reconsider what tools you are using. I am forever grateful that an awesome geneticist who needed help bootstrapping tech infra took the time to teach me, a greybeard sysadmin type, practical, reproducible science, from paper to implimentation. I learned a lot but the biggest downside is, after being heavily surrounded by scientists in the workplace in most jobs since then, I find companies without that difficult to work for.
- coliveira 3y agoThe difference is that learning pearl is an ordeal that will take several weeks at the minimum. Learning awk can be done in one afternoon, after reading a man page and a few examples. And it really works for the tasks it was designed. So I think awk is superior to perl for the purpose it was created.
- thesuperbigfrog 3y ago>> The difference is that learning pearl is an ordeal that will take several weeks at the minimum. I am not sure about pearl, but Perl is not that different from most other programming languages. If you are familiar with Javascript or Python, learning the basics of Perl is pretty easy: https://perldoc.perl.org/perlintro https://perldoc.perl.org/perlintro https://www.perltutorial.org/ https://www.perltutorial.org/ Perl is designed for text processing, so it has a powerful regular expression engine. Writing regular expressions can be difficult, but it is a great skill to have in your toolkit. Fun Fact: If the programming language you are using has support for regular expressions, they are almost certainly Perl-compatible regular expressions because Perl's regular expression syntax is more widely used and more popular than other regular expression syntaxes (e.g. POSIX, etc.).