Submitted yesterday:
Learn to use Awk with hundreds of examples
https://github.com/learnbyexample/Command-line-text-processi...
https://github.com/learnbyexample/Command-line-text-processi...
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...
* http://www.compciv.org/unix-tools/
* https://www.commandlinefu.com/commands/browse/sort-by-votes
* https://linoxide.com/linux-how-to/linux-commands-brief-outli...
* https://github.com/learnbyexample/Command-line-text-processi... --> this is my own repo on text processing commands like grep/sed/awk/sort/pr/paste/etc
Bonus:
* https://github.com/jlevy/the-art-of-command-line
* https://stackoverflow.com/questions/68372/what-is-your-singl...
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 :)
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...
[1] https://github.com/learnbyexample/Command-line-text-processi...
* 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...
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...
[1] https://github.com/learnbyexample/Command-line-text-processi...
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.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...
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...
[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 have a collection for ruby one-liners too [1]
[1] https://github.com/learnbyexample/Command-line-text-processi...
[1] https://github.com/learnbyexample/Command-line-text-processi...
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...
# 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...
https://github.com/learnbyexample/Command-line-text-processi...
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/etcFurther 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...
agree with getting more stars, but donation? not yet :-/ :( https://github.com/learnbyexample/Command-line-text-processi...
short-descriptions and tons of examples.. I had fun and learned a lot doing this
link: https://github.com/learnbyexample/Command-line-text-processi...
if you're interested, you could give my tutorial(https://github.com/learnbyexample/Command-line-text-processi...) a try
it has over 300 examples..
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 :)