Skip awk, use perl.... The alias below sets perl to loop over STDIN splitting each line on more than one whitespace character and populate an array F. The -nE will then Evaluate an expression from the command line looping over the input line-by-line. alias glorp='perl -aF"/\s+/" -nE' So now we have the command `glorp` to play with which has more familiar syntax than awk and all of CPAN available to play with! $ [data…
Skip grep, use awk
91–100 of 136 posts
Re: Skip grep, use awk
#92Re: Skip grep, use awk
#93I'd like to share a recent experience on a related note, but in the opposite spirit - rather than reduce the number of command invocations on a command line, it may make sense to increase it. I had a loop operating on a text file like this: while read line do echo "$line" | sed -e "s/A/X/" -e "s/B/Y/" -e "s/C/Z/" ... Gradually, as I added more things to replace, I noticed severe slowdown. Things got fast again when I…
Re: Skip grep, use awk
#94Skip awk, use perl.... The alias below sets perl to loop over STDIN splitting each line on more than one whitespace character and populate an array F. The -nE will then Evaluate an expression from the command line looping over the input line-by-line. alias glorp='perl -aF"/\s+/" -nE' So now we have the command `glorp` to play with which has more familiar syntax than awk and all of CPAN available to play with! $ [data…
Hey, it would be awesome to have something like this for Python!
However, Ruby completely inherited this aspect of Perl and is another good candidate. It's just even old systems have a perl installed that will perform the awk like functionality.
Re: Skip grep, use awk
#95Skip awk, use perl.... The alias below sets perl to loop over STDIN splitting each line on more than one whitespace character and populate an array F. The -nE will then Evaluate an expression from the command line looping over the input line-by-line. alias glorp='perl -aF"/\s+/" -nE' So now we have the command `glorp` to play with which has more familiar syntax than awk and all of CPAN available to play with! $ [data…
Hey, it would be awesome to have something like this for Python!
Re: Skip grep, use awk
#96Skip awk, use perl.... The alias below sets perl to loop over STDIN splitting each line on more than one whitespace character and populate an array F. The -nE will then Evaluate an expression from the command line looping over the input line-by-line. alias glorp='perl -aF"/\s+/" -nE' So now we have the command `glorp` to play with which has more familiar syntax than awk and all of CPAN available to play with! $ [data…
alias glorp='ruby -ane '
$ [data is generated] | glorp ' ~ /Something/ and puts $F[2]'
Or: $ echo -e '{"hello":"world"}\n{"hello":"cat"}' | glorp 'puts JSON.load($_)["hello"] ' -rjson
(Of course Ruby got the -a autosplit-mode and the -n assumed 'while gets(); ... end' loop from Perl along with $_ and $F, so it's very intentional that they're similar)Re: Skip grep, use awk
#97Earlier quoted context omitted.
That's what I was referencing when I said > Pulling out a field from a line is what most people use awk for, but it's honestly the least interesting part of awk. In fact, if cut supported regular expressions for specifying the field and record separators people wouldn't be using awk for that purpose (because that's all that $n does). There's nothing magical about awk's default FS. It's literally just /\s+/. If cut's…
I wish the default 'cut' implementation could be just a little more clever - regex delimiters would be good, it doesn't even support multiple characters :( Also, cut's output manipulation is surprising. '-f 2,1' is actually the same as '-f 1,2' - you can't change the order of printing. I know there are other programs that can do the job, but it's a little frustrating when you can 'almost' get there with a chain of pi…
Re: Skip grep, use awk
#98Skip awk, use perl.... The alias below sets perl to loop over STDIN splitting each line on more than one whitespace character and populate an array F. The -nE will then Evaluate an expression from the command line looping over the input line-by-line. alias glorp='perl -aF"/\s+/" -nE' So now we have the command `glorp` to play with which has more familiar syntax than awk and all of CPAN available to play with! $ [data…
Here's the equivalent for Ruby: alias glorp='ruby -ane ' $ [data is generated] | glorp ' ~ /Something/ and puts $F[2]' Or: $ echo -e '{"hello":"world"}\n{"hello":"cat"}' | glorp 'puts JSON.load($_)["hello"] ' -rjson (Of course Ruby got the -a autosplit-mode and the -n assumed 'while gets(); ... end' loop from Perl along with $_ and $F, so it's very intentional that they're similar)
Re: Skip grep, use awk
#99Earlier quoted context omitted.
Hey, it would be awesome to have something like this for Python!
Not really possible in Python for anything overly useful/complex because of the significant white space, and regular expressions are not a first class object in the language. ipython is the equivalent solution I suppose. However, Ruby completely inherited this aspect of Perl and is another good candidate. It's just even old systems have a perl installed that will perform the awk like functionality.
https://code.google.com/archive/p/pyp/
"Pyp is a linux command line text manipulation tool similar to awk or sed, but which uses standard python string and list methods as well as custom functions evolved to generate fast results in an intense production environment."
Re: Skip grep, use awk
#100Earlier quoted context omitted.
Hey, it would be awesome to have something like this for Python!
Not really possible in Python for anything overly useful/complex because of the significant white space, and regular expressions are not a first class object in the language. ipython is the equivalent solution I suppose. However, Ruby completely inherited this aspect of Perl and is another good candidate. It's just even old systems have a perl installed that will perform the awk like functionality.
Of course, you can do all of this in Python, just not as a one liner.