learnbyexample

joined 2 years ago
[–] [email protected] 6 points 4 days ago (1 children)

Well, if you are comfortable with Python scripts, there's not much reason to switch to awk. Unless perhaps you are equating awk to Python as scripting languages instead of CLI usage (like grep, sed, cut, etc) as my ebook focuses on. For example, if you have space separated columns of data, awk '{print $2}' will give you just the second column (no need to write a script when a simple one-liner will do). This of course also allows you to integrate with shell features (like globs).

As a practical example, I use awk to filter and process particular entries from financial data (which is in csv format). Just a case of easily arriving at a solution in a single line of code (which I then save it for future use).

 

Hello!

I am pleased to announce a new version of my CLI text processing with GNU awk ebook. This book will dive deep into field processing, show examples for filtering features, multiple file processing, how to construct solutions that depend on multiple records, how to compare records and fields between two or more files, how to identify duplicates while maintaining input order and so on. Regular expressions will also be discussed in detail.

Book links

To celebrate the new release, you can download the PDF/EPUB versions for free till 06-April-2025.

Or, you can read it online at https://learnbyexample.github.io/learn_gnuawk/

Interactive TUI apps

Feedback

I would highly appreciate it if you'd let me know how you felt about this book. It could be anything from a simple thank you, pointing out a typo, mistakes in code snippets, which aspects of the book worked for you (or didn't!) and so on.

Happy learning :)

[–] [email protected] 1 points 1 month ago

I'll recommend some from the lesser known progression fantasy genre:

  • Cradle by Will Wight
  • Mage Errant by John Bierce
  • Mother of Learning by Nobody103 (Domagoj Kurmaić)
  • The Weirkey Chronicles by Sarah Lin
  • Beware of Chicken by CasualFarmer
  • Super Powereds by Drew Hayes
19
CPU performance (curiouscoding.nl)
[–] [email protected] 2 points 1 month ago

Not my site, just sharing a link I saw on HN.

29
GNU awk idioms explained (learnbyexample.github.io)
[–] [email protected] 1 points 1 month ago

Well, I'm not going to even try understanding the various features used in that sed command. I do know how to use basic loops with labels, but I never bothered with all the buffer manipulation stuff. I'd rather use awk/perl/python for those cases.

[–] [email protected] 2 points 1 month ago (2 children)

This might work, but I think it is best to not tinker further if you already have a working script (especially one that you understand and can modify further if needed).

perl -pe 's/\[[^]]+\]\((?!https?)[^#]*#\K[^)]+(?=\))/lc $&=~s:%20|\d\K\.(?=\d):-:gr/ge'
[–] [email protected] 1 points 2 months ago (1 children)

Hmm, OP mentioned "Only edit what’s between parentheses" - don't see anywhere that whole URL shouldn't be changed...

[–] [email protected] 2 points 2 months ago* (last edited 2 months ago) (7 children)

Here's a solution with perl (assuming you don't want to change http/https after the start of ( instead of start of a line):

perl -pe 's/\[[^]]+\]\(\K(?!https?)[^)]+(?=\))/lc $&=~s|%20|-|gr/ge' ip.txt
  • e flag allows you to use Perl code in the substitution portion.
  • \[[^]]+\]\(\K match square brackets and use \K to mark the start of matching portion (text before that won't be part of $&)
  • (?!https?) don't match if http or https is found
  • [^)]+(?=\)) match non ) characters and assert that ) is present after those characters
  • $&=~s|%20|-|gr change %20 to - for the matching portion found, the r flag is used to return the modified string instead of change $& itself
  • lc is a function to change text to lowercase
[–] [email protected] 7 points 2 months ago (1 children)
[–] [email protected] 2 points 2 months ago

Check out my chapter on GNU grep BRE/ERE for those wanting to learn this regex flavor: https://learnbyexample.github.io/learn_gnugrep_ripgrep/breere-regular-expressions.html (there's also another chapter for PCRE)

[–] [email protected] 2 points 3 months ago

Memory, Sorrow, and Thorn by Tad Williams

[–] [email protected] 3 points 3 months ago

I use Vim ;)

Python itself provides IDLE, which is good enough for beginners. https://thonny.org/ is another good one for beginners.

As mentioned by others, Jetbrains is good for many languages. https://www.kdevelop.org/ is another option.

view more: next ›