News for hackers. Stuff that matters.
Re:Chess Written in GNU Sed by GNOMES on Monday October 16, 2023 @02:38PM (#37904165)
I really need to invest more time into Sed/Awk. I typically only use them for find/replace or deleting characters/lines in my shell scripts.
Re:Chess Written in GNU Sed by jmholla on Monday October 16, 2023 @04:35PM (#37906184)
I've shared this before, but this sed tutorial made me a pro. [0] Even if you don't use it for more complex things, you may find there are faster ways to do the things you are now.

[0]: https://www.grymoire.com/Unix/Sed.html

Edit: That said, I don't even want to start dissecting the submitted code.

Re:Chess Written in GNU Sed by DryLabRebel on Tuesday October 17, 2023 @02:12AM (#37911234)
Grymoire is how I learned sed, and is a fantastic quick reference for grep and regex also.
Re:Chess Written in GNU Sed by chasil on Monday October 16, 2023 @04:52PM (#37906445)
For awk, start with the book by Kernighan/Aho/Weinberger. The PDF of the first edition is freely available on archive.org, and a second edition has been announced. Chapter 2 of the first edition is only 40 pages, and describes all language features.

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

For sed, the best resource is likely the free "UNIX Bookshelf" from O'Reilly that can be found online; this contains a book specifically focusing on Sed and Awk.

https://freecomputerbooks.com/The-Unix-CD-Bookshelf-Version-...

Re:Chess Written in GNU Sed by Brentward on Monday October 16, 2023 @05:13PM (#37906723)
The second edition is out! I started reading it last week, and it's great so far.

https://www.awk.dev/

Re:Chess Written in GNU Sed by rjh29 on Monday October 16, 2023 @06:45PM (#37907674)
Just use Perl for one-liners. It's more powerful than sed/awk but it does pretty much everything those do.
Re:Chess Written in GNU Sed by garciasn on Monday October 16, 2023 @07:16PM (#37908005)
Perl is probably overkill for 99% of one-liners and may not be available on as many environments as awk/sed are, but I advocate that folks do whatever is best for them in their environment and if that's Perl for you, rock it out!
Re:Chess Written in GNU Sed by nickpeterson on Monday October 16, 2023 @11:04PM (#37910056)
If Perl isn’t available in the environment try ‘systemctl start oyster-farm’
Re:Chess Written in GNU Sed by anthk on Monday October 16, 2023 @08:02PM (#37908366)
awk can do much more than sed. And, with patience, you could even write a Z-machine interpreter on it as some guy did with postscript. You might have to convert the binary input to hex first with xxd/od in order to parse the opcodes in a nice way, but everything else would be simulated from awk.
Re:Chess Written in GNU Sed by tyingq on Monday October 16, 2023 @08:59PM (#37908915)
> You might have to convert the binary input to hex first

If you're okay with gawk, most implementations ship with gawkextlib, which has readfile(), and then you have FIELDWIDTHS.

Re:Chess Written in GNU Sed by asicsp on Monday October 16, 2023 @11:10PM (#37910099)
I have ebooks on GNU sed and GNU awk with plenty of examples and exercises (free to read online):

* https://learnbyexample.github.io/learn_gnused/

* https://learnbyexample.github.io/learn_gnuawk/

I also wrote TUI apps for interactive exercises (grep, sed, awk, etc): https://github.com/learnbyexample/TUI-apps

Re:Chess Written in GNU Sed by nvy on Monday October 16, 2023 @11:44PM (#37910322)
This taught me awk, from an HN submission years ago: https://ferd.ca/awk-in-20-minutes.html

I've had some fun using awk to generate C# classes for an Ultima Online emulator.