Janis Papanagnou wrote:
> On 25.10.2015 07:58, Thomas 'PointedEars' Lahn wrote:
>> Janis Papanagnou wrote:
>>> On 24.10.2015 23:25, Thomas 'PointedEars' Lahn wrote:
>>>> Janis Papanagnou wrote:
>>>>> Try using awk's printf instead of using system() resp. a shell...
>>>>>
>>>>> awk -F, '/^vpn/ { printf "%s", $NF | "base64 -d" }'
>>>
>>> (typo, missing -F, fixed)
>>>
>>>> Hammer, nail. Obviously this inefficient overkill is not going to
>>>> solve the problem. (Determining the problem is that trivial that it is
>>>> left as an exercise to the reader for now.)
>>>
>>> Using a text processor to extract only parts of only some selected
>>> records and pass them to one single process to work on that seems
>>> efficient and to the point. - Why do you think this method is
>>> inefficient? Or even overkill?
>>
>> To begin with, it is not equivalent to the original approach, which takes
>> the curl(1) output, and processes only the *first* occurrence (“grep … |
>> head -1”) of “vpn” on the beginning of a line (“^”). By contrast, your
>> awk program processes *all* lines that begin with “vpn”.
>
> I was responding to a posting where I don't see any grep.
Yes, AISB, you did not see the whole picture.
>> Second, if you apply the awk(1) solution to what is already there, you
>> would be executing awk in a subshell (thanks to the pipe),
>
> No, that depends on the shell. The shell I use, for example, ksh, will run
> the final pipe process in the current shell.
How did you get that idea?
,-[ksh93 manual]
|
| A pipeline is a sequence of one or more commands separated by |. The
| standard output of each command but the last is connected by a pipe(2) to
| the standard input of the next command. Each command, except possibly the
^^^^^^^^
| last, is run as a separate process; the shell waits for the last command
^^^^^^^^^^^^^^^^
| to terminate.
,-[bash 4.x manual]
|
| […]
| Each command in a pipeline is executed as a separate process (i.e., in a
^^^^^^^^^^^^^^^^
| subshell).
^^^^^^^^
>> then run base64(1) in a shell (“"…"”)
>
> Why do you think so?
You ripped the relevant parts apart. The sentence continues with “from
awk”.
> Hyongi's system() will create a shell instance, yes.
_Hongyi_
> The pipe in awk-syntax will not; my understanding is that awk exec's the
> process that is quoted after the pipe and opens a pipe communication
> channel to that process. Do you disagree?
Yes, I do.
<
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/awk.1?query=awk>
<
http://manpages.debian.org/cgi-bin/man.cgi?query=awk&sektion=&apropos=0&manpath=Debian%207.0%20wheezy>
The description there is a big vague (I even almost overlooked “|cmd”), but
I think if you run the command this way a shell is required to separate the
arguments. The gawk manual has it explicitly:
<
http://www.gnu.org/software/gawk/manual/html_node/Redirection.html#index-pipe_002c-output>
|
| print items | command
|
| It is possible to send output to another program through a pipe instead of
| into a file. This redirection opens a pipe to command, and writes the
| values of items through this pipe to another process created to execute
| command.
|
| The redirection argument “command” is actually an awk expression. Its
| value is converted to a string whose contents give the shell command to be
^^^^^^^^^^^^^
| run.
>> from awk only to do what the subshell could have done in the
>> first place.
>
> (So I think your assumptions were wrong and thus your conclusions as
> well.)
(Your logic is flawed: “Ex falso quodlibet” means that from wrong
assumptions can be concluded *anything* – wrong *and* correct statements.)
>> Granted, usually “awk -F… '/…/ { … }' is probably more efficient than
>> “grep … | while IFS=… read; do … done”,
>
> Not "usually"; it's generally more efficient.
Evidentially it is not.
> Shell loops are known to be inperformant, specifically if compared to
> tools that loop natively.
There is only one line to be processed here. One does not even need a loop.
>> but you have to see the whole picture.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> Running awk this way on a single line (if you modified your awk program)
>> when IFS would do *is* inefficient overkill.
>
> No one was running awk on a single line in the posted example that I was
> replying to.
I have marked the important part.