What does HackerNews think of Command-line-text-processi?

Awk is an amazingly effective tool for getting things done quickly.

Submitted yesterday:

Learn to use Awk with hundreds of examples

https://github.com/learnbyexample/Command-line-text-processi...

https://news.ycombinator.com/item?id=33349930

I had a similar experience with one of my GitHub repos [0] that is currently 9k+ stars. I added donation link when it was about 5k stars (after it went viral courtesy HN). But this was before GitHub sponsors. I removed donation links after I got only a single donation in about a year.

I had much better results when I started converting my tutorials into ebooks and sold them. Obviously having a paid product is different, but I'm referring to the paid sales I got whenever I put up 'pay what you want' offer.

[0] https://github.com/learnbyexample/Command-line-text-processi...

Hello!

I had started tutorials on command line text processing (https://github.com/learnbyexample/Command-line-text-processi...) more than three years back. I learnt a lot writing them and continue to learn more with experience.

I finished first version of cookbook on Perl one-liners recently. With that, five of the major chapters from that repo are now accessible as better formatted ebooks, updated for newer software versions, exercises, solutions, etc.

You can download pdf/epub versions of the ebooks using the links below (free until this Sunday)

* Perl one-liners cookbook: https://gumroad.com/l/perl-oneliners or https://leanpub.com/perl-oneliners

* Five book bundle of grep/sed/awk/perl/ruby one-liners: https://gumroad.com/l/oneliners or https://leanpub.com/b/oneliners

---

I'd highly appreciate your feedback and hope that you find these resources useful. Happy learning and stay safe :)

Someone else already asked for perl one-liners in this thread. I started with command line text processing repo [1] about three years back. That has a chapter on grep/sed/awk/perl/ruby one-liners along with many other tools. I may convert perl one-liners to a book as well later.

Python's default 're' module does indeed lack many features, but there's 'regex' third party module that would be easier to adapt for perl users.

[1] https://github.com/learnbyexample/Command-line-text-processi...

I started with command line text processing repo [1] about three years back. That has a chapter on grep/sed/awk/perl/ruby one-liners along with many other tools. I may convert perl one-liners to a book as well later.

[1] https://github.com/learnbyexample/Command-line-text-processi...

Nice! A few suggestions if I may:

* please consider using the same prompt for all examples, a few of them start with `code` while some others start with `awk book` and some do not have any prompt at all

* split long chapters into smaller sections plus add section headings as links at the start of chapter

* please please please avoid parsing ls [1] you could either reuse `sales.csv` or create another sample file instead of using `ls` as source of input... for example, your `ls -l | awk '$NF ~ /c/ {print}'` example will not work if a file is name `code xyz` (note the space)

Also, I have a similar example based hundreds of gawk one-liners [2] tutorial, which I'm currently working towards publishing as a book this month with better examples, descriptions, new regex chapter, etc

[1] https://unix.stackexchange.com/questions/128985/why-not-pars...

[2] https://github.com/learnbyexample/Command-line-text-processi...

Just for anyone else, you could probably end up in a similar corner with perl - but in both cases it's likely a case of "holding it wrong" - ruby borrows heavily from perl which borrowed heavily from shell with sed, awk, grep, cut and friends.

So this kind of thing should be quite doable in a short ruby script - or a few short scripts - albeit written in "shell" style, with eg '-n or -p (wrap code in "while gets...end",-p with "puts _"), probably along with -a (automatically split lines).

Its in some senses an entirely different dialect of ruby, though.

Some examples here:

https://github.com/learnbyexample/Command-line-text-processi...

I have a repo dedicated for some of the cli text processing tools like grep/sed/awk/perl/sort/etc. Here's my one-liner collection for awk [1]

[1] https://github.com/learnbyexample/Command-line-text-processi...

Perl's problem is that it's more confusing than it is powerful.

I think most of the people who were into Perl for the "beauty" ended up going to ruby.

People who were into it for CPAN went to python.

You might find this interesting, as you can see the spirit is alive and well: https://github.com/learnbyexample/Command-line-text-processi...

  ruby -0ane 'print $F.shuffle[0..3].join,"\n"' < /usr/share/dict/words
If you're intrigued by the idea of perl one-liners, go explore ruby.
Reminds me of a similar article [1]

Once you get a hang of how shell constructs like pipes, redirections, globs, variable/command substitutions, etc, the various cli text processing tools like grep, sed, awk, perl, sort, tr, pr, paste, etc are worth to learn at least the basics. They have been through years of use and heavily optimized for performance. Just today, a friend of mine called to ask how to improve a Python script's performance for 5-10 MB text file. After confirming he isn't using any other special modules, I advised to check if the performance improves by implementing it using awk.

If anyone's interested in examples based tutorials on cli text processing tools, check out my github repo [2]

[1] https://blog.jpalardy.com/posts/why-learn-awk/

[2] https://github.com/learnbyexample/Command-line-text-processi...

I made a compilation of Ruby one-liners [1] as well last year.

There's plenty of stuff that is similar to Perl, which in turn had borrowed from awk, sed and other tools. The biggest difference I'd pick is Perl's context based operation.

    # Ruby requires explicit conversion with to_i
    ruby -ane 'print if $F[1].to_i > 35'
    perl -ane 'print if $F[1] > 35'
Performance is slower compared to Perl, but to those who already know Ruby, this would suit better than learning the nuances of another language.

[1] https://github.com/learnbyexample/Command-line-text-processi...

I have a curated list of resources[1] on topics like learning command line basics, bash scripting, style guide, etc. I have also have my own basics guide[2] and a comprehensive cli text processing repo[3]

[1] https://github.com/learnbyexample/scripting_course/blob/mast...

[2] https://github.com/learnbyexample/Linux_command_line

[3] https://github.com/learnbyexample/Command-line-text-processi...

I'd say it is more similar to perl than awk for options like -F -l -a -n -e -0 etc. And perl borrowed stuff from sed, awk, etc

I have a collection for ruby one-liners too [1]

[1] https://github.com/learnbyexample/Command-line-text-processi...

I have a collection of such one-liners, for duplicates including how to form key for multiple fields, see [1]

[1] https://github.com/learnbyexample/Command-line-text-processi...

I haven't tried it yet, but it would depend on what sort of features you need

Python wouldn't be a good choice for cli usage

Perl is awesome to use from cli, and it is not just simple search and replace, see my tutorial[1] if you want to see examples

sed and awk are awesome on their own for cli usage, sed is meant for line oriented tasks and awk for field oriented ones (there is overlap too) - one main difference compared to perl is that their regex is BRE/ERE which is generally faster but lacks in many features like lookarounds, non-greedy, named capture groups, etc

you could check out sd[2] for a Rust implementation of sed like search and replacement (small subset of sed features)

[1] https://github.com/learnbyexample/Command-line-text-processi...

[2] https://github.com/chmln/sd

some notes on the sample awk/sed/perl one-liner given:

    # input line has to be explicitly printed
    awk '{gsub(/Jack/,"Jill")} 1' file.txt

    # -i will do inplace editing, unlike the awk command
    # -i by itself won't work on non-GNU versions, needs backup extension
    sed 's/Jack/Jill/g' file.txt

    # use single quotes always, unless double is needed
    # -p will behave like default sed
    perl -pe 's/Jack/Jill/g' file.txt
personally, I prefer the terseness of these commands over verbose SQL like syntax (and also the fact that I don't know SQL like tools)

However, I would agree that initial learning curve is tough for sed/awk/perl. Once you get familiar with their idioms, they become the swiss army knife of cli text processing (along with grep). I have an entire repo dedicated to such tools[1]

[1] https://github.com/learnbyexample/Command-line-text-processi...

I have an example based tutorial for all these commands plus other cli text processing commands

https://github.com/learnbyexample/Command-line-text-processi...

for your given sample, you could use awk[0] as well

    awk 'NR>1{print $2}'
or ruby[1]

    ruby -ane 'puts $F[1] if $.>1'
which one to use depends on lots of factor - speed, features, availability, etc as well as whether user already knows perl[2]/ruby/etc

Further reading(disclosure: I wrote these)

[0]: https://github.com/learnbyexample/Command-line-text-processi...

[1]: https://github.com/learnbyexample/Command-line-text-processi...

[2]: https://github.com/learnbyexample/Command-line-text-processi...

>Well-known project with 5000 stars? Here, have more stars. Here, have more donations

agree with getting more stars, but donation? not yet :-/ :( https://github.com/learnbyexample/Command-line-text-processi...

I have a repo dedicated to cli text-processing..

short-descriptions and tons of examples.. I had fun and learned a lot doing this

link: https://github.com/learnbyexample/Command-line-text-processi...

one-liners are fun though, especially if you like code golfing..

if you're interested, you could give my tutorial(https://github.com/learnbyexample/Command-line-text-processi...) a try

it has over 300 examples..

for the ls parsing example, you can do

shopt -s nocaseglob

ls ~/Downloads/*.{png,jpg,jpeg,gif,webp}

----

for command line tools (grep/sed/awk/sort/etc), you can refer my ongoing project (https://github.com/learnbyexample/Command-line-text-processi...) as resource :)