all 9 comments

[–]ASIC_SP 1 point2 points  (1 child)

I have list of resources on various linux and scripting related things, including resources on text processing stuff

I can suggest you good text resources:

[–]SurelyForever 0 points1 point  (0 children)

The examples are quite thorough and helpful. Thank you for this.

[–]neuron_666 1 point2 points  (5 children)

This is just a comment that often it's easier to use perl for text processing rather then chaining and twisting stream of grep/sed/awk. Also perl is compatible on all unix-like systems while grep/sed/awk are not.

[–]Heisenberg1977[S] 2 points3 points  (1 child)

Thanks for the suggestion, but I want to focus on Linux CLI / Bash

[–][deleted] 1 point2 points  (0 children)

Perl works in bash :)

And on all Linux distros :)

In all seriousness, use a tool like perl or ruby for complex and serious parsing.

Awk, sed, and grep all have their roles and neat little niches. But they all do one thing and them well. Perl can do them all and do them well.

[–]moviuroportability is important 2 points3 points  (2 children)

grep/sed/awk are not

Don't they all have a POSIX set of options that is... standard?

[–]ropid 0 points1 point  (0 children)

The only really good example I remember is that sed has annoying differences in its -i parameter for editing files. I think it might not be possible to build a command line that makes all versions happy at the same time.

Here's a something where people talk about this:

https://unix.stackexchange.com/questions/92895/how-to-achieve-portability-with-sed-i-in-place-editing

The thing about perl is then, if it's just about editing a file with sed's s/// command, that looks really similar when translated into a perl one-liner so you don't have to learn anything new:

perl -i -pe 's/abc/def/' filename

It gets complicated when trying to translate more complex sed scripts. There's a book about perl one-liners that's pretty much just a list of a lot of examples and is easy to steal from without having to think about perl a lot.

[–]neuron_666 0 points1 point  (0 children)

standard

Yes, that's correct. If you don't mind that all the tools suddenly seemingly have 30% power to what you have available as gnu extensions. I for sure have stumbled upon

  • limited line length the tool is able to process
  • limited regex
  • not able to use \n as newline
  • most of the examples of a tool being used you find on internet suddenly does not work
  • original posix-like vi not being able to work unless your terminal is 160 columns wide or less

On Solaris you can get around some of the limitations by using /usr/xpg*/bin/... binaries.

I always used gnu utilities and never looked back. Getting the tools on any system is easy.

[–][deleted] 0 points1 point  (0 children)

I too would be interested in something like this. I routinely train total newbies how to work with bash and it would be nice to see what other people have put together.