Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #1123 > unrolled thread
| Started by | no.top.post@gmail.com |
|---|---|
| First post | 2011-05-17 06:27 +0000 |
| Last post | 2011-06-06 04:58 +0000 |
| Articles | 20 on this page of 22 — 9 participants |
Back to article view | Back to comp.os.linux.misc
Re: HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-17 06:27 +0000
Re: HOW2 pass args to awk? Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-05-17 09:12 +0200
Re: HOW2 pass args to awk? Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> - 2011-05-17 00:21 -0700
Re: HOW2 pass args to awk? Harold Stevens <wookie@jimbo.localdomain> - 2011-05-17 09:17 -0500
Re: HOW2 pass args to awk? Aragorn <aragorn@chatfactory.invalid> - 2011-05-17 17:36 +0200
Re (2): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-29 15:56 +0000
Re: Re (2): HOW2 pass args to awk? Bill Marcum <bill@lat.localnet> - 2011-05-29 13:05 -0400
Re (3): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-30 02:22 +0000
Re: Re (3): HOW2 pass args to awk? Aragorn <aragorn@chatfactory.invalid> - 2011-05-30 05:09 +0200
Re: HOW2 pass args to awk? Bill Marcum <bill@lat.localnet> - 2011-05-17 07:55 -0400
Re (2): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-29 15:56 +0000
Re: Re (2): HOW2 pass args to awk? Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-29 17:46 +0000
Re (3): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-30 02:22 +0000
Re: Re (3): HOW2 pass args to awk? Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-30 09:01 +0000
Re: Re (3): HOW2 pass args to awk? and more Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-31 11:05 +0000
Re: Re (3): HOW2 pass args to awk? and more Ralf Fassel <ralfixx@gmx.de> - 2011-05-31 14:35 +0200
Re: Re (3): HOW2 pass args to awk? and more Ed Morton <mortonspam@gmail.com> - 2011-05-31 07:56 -0500
Re: Re (3): HOW2 pass args to awk? and more Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-31 14:14 +0000
Re: Re (3): HOW2 pass args to awk? and more Ralf Fassel <ralfixx@gmx.de> - 2011-06-01 10:41 +0200
Re (4): HOW2 pass args to awk? and more no.top.post@gmail.com - 2011-06-06 10:26 +0000
Re: Re (4): HOW2 pass args to awk? and more Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-06-06 14:01 +0000
Re (4): HOW2 pass args to awk? and more no.top.post@gmail.com - 2011-06-06 04:58 +0000
Page 1 of 2 [1] 2 Next page →
| From | no.top.post@gmail.com |
|---|---|
| Date | 2011-05-17 06:27 +0000 |
| Subject | Re: HOW2 pass args to awk? |
| Message-ID | <iqt4hb$fcn$1@dont-email.me> |
Bob Harris wrote:-
> awk '
> BEGIN {
> arg1 = ARGV[1] <-- *
> arg2 = ARGV[2]
> arg3 = ARGV[3]
> for(j=4; j < ARGC; j++) {
> ARGV[j-3] = ARGV[j]
> }
> ARGC = ARGC - 3
> }
> ...
> ... your stuff here ...
> ...
> ' "Class:" "cow" "mouse" file1 file2 file3 file4 ...
>
> As you can see ARGV usage is a bit awkward.
--
I had suspected that ARGV could do it.
But it fails. Are you fooling with me?
gawk '
BEGIN {
arg1 = ARGV[1]
arg2 = ARGV[2]
print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised
}'
exit
/arg1/&&/arg2/{print FILENAME ":" $0}'\
`find /mnt/p11/PhysicalSpace/DirTest -type f`
------------
All I need to do is pass 2 arguments,
instead of 'hardwireing them in',
and getting another script to edit them.
== Chris Glur.
[toc] | [next] | [standalone]
| From | Janis Papanagnou <janis_papanagnou@hotmail.com> |
|---|---|
| Date | 2011-05-17 09:12 +0200 |
| Message-ID | <iqt74h$eqi$1@news.m-online.net> |
| In reply to | #1123 |
On 17.05.2011 08:27, no.top.post@gmail.com wrote: > -- > I had suspected that ARGV could do it. > But it fails. Are you fooling with me? No, certainly not. But unfortunately there's a problem on your end of the communication channel; you are resistant to advice it seems. All necessary information has been presented. In which ways does it fail? Show what you've done and we'll show you what you've done wrong. Provide the necessary information; your environment, your data, how you called it, your results, and the expected results. Or are you just fooling with us?
[toc] | [prev] | [next] | [standalone]
| From | Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> |
|---|---|
| Date | 2011-05-17 00:21 -0700 |
| Message-ID | <28k9a8x6jd.ln2@goaway.wombat.san-francisco.ca.us> |
| In reply to | #1125 |
["Followup-To:" header set to comp.os.linux.misc.] On 2011-05-17, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote: > On 17.05.2011 08:27, no.top.post@gmail.com wrote: > > No, certainly not. But unfortunately there's a problem on your end of the > communication channel; you are resistant to advice it seems. All necessary > information has been presented. This is fairly typical behavior for the OP, unfortunately. --keith -- kkeller-usenet@wombat.san-francisco.ca.us (try just my userid to email me) AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt see X- headers for PGP signature information
[toc] | [prev] | [next] | [standalone]
| From | Harold Stevens <wookie@jimbo.localdomain> |
|---|---|
| Date | 2011-05-17 09:17 -0500 |
| Message-ID | <slrnit50rl.2ru.wookie@jimbo.localdomain> |
| In reply to | #1126 |
In <28k9a8x6jd.ln2@goaway.wombat.san-francisco.ca.us> Keith Keller: [Snip...] > This is fairly typical behavior for the OP, unfortunately. FWIW, no.top.post hit my bozobin too long ago to remember exactly when. -- Regards, Weird (Harold Stevens) * IMPORTANT EMAIL INFO FOLLOWS * Pardon any bogus email addresses (wookie) in place for spambots. Really, it's (wyrd) at airmail, dotted with net. DO NOT SPAM IT. I toss GoogleGroup (http://twovoyagers.com/improve-usenet.org/).
[toc] | [prev] | [next] | [standalone]
| From | Aragorn <aragorn@chatfactory.invalid> |
|---|---|
| Date | 2011-05-17 17:36 +0200 |
| Message-ID | <iqu4mj$ho7$82@dont-email.me> |
| In reply to | #1126 |
On Tuesday 17 May 2011 09:21 in comp.os.linux.misc, somebody identifying as Keith Keller wrote... > ["Followup-To:" header set to comp.os.linux.misc.] > > On 2011-05-17, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote: > >> [...] But unfortunately there's a problem on your end of the >> communication channel; you are resistant to advice it seems. All >> necessary information has been presented. > > This is fairly typical behavior for the OP, unfortunately. I will confirm that. -- *Aragorn* (registered GNU/Linux user #223157)
[toc] | [prev] | [next] | [standalone]
| From | no.top.post@gmail.com |
|---|---|
| Date | 2011-05-29 15:56 +0000 |
| Subject | Re (2): HOW2 pass args to awk? |
| Message-ID | <irtqc6$9mh$1@dont-email.me> |
| In reply to | #1125 |
In article <iqt74h$eqi$1@news.m-online.net>, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> On 17.05.2011 08:27, no.top.post@gmail.com wrote:
> > --
> > I had suspected that ARGV could do it.
> > But it fails. Are you fooling with me?
>
> No, certainly not. But unfortunately there's a problem on your end of the
> communication channel; you are resistant to advice it seems. All necessary
> information has been presented.
>
> In which ways does it fail? Show what you've done and we'll show you what
> you've done wrong. Provide the necessary information; your environment,
> your data, how you called it, your results, and the expected results.
>
Since you seem incapable of extracting the essence: HOW2 pass args to awk,
which was repeatedly addressed by other writers, I give you the whole story.
I want to have the location of files, in a special dir-tree, listed which have
a line containing "CLASS:" and <argString> in the same line.
Crrently I use the script - with no args:---
#!/bin/bash
awk '/Class:/&&/TLC/{print FILENAME}'\
`find /mnt/p11/PhysicalSpace/DirTest -type f`
------------
And I've got corresponding scripts for 'OCGE' & 'JK80K' ...etc. for
several other strings besides "TLC".
From my previous post, which you've snipped:
> > gawk '
> > BEGIN {
> > arg1 = ARGV[1]
> > arg2 = ARGV[2]
> > print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised
> > }'
> >
> > exit
> > /arg1/&&/arg2/{print FILENAME ":" $0}'\
> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
isn't it obvious that if, at the line indicated the arg1 has not
been 'extracted', that the guts of the routine [below `exit`]
will fail TO DO WHAT I INTEND?
The output of: ./<theScript> dog
is: 'arg1='
How would you, confirm that 'arg1', which has been passed to the script
as the first arg, has been 'extracted', to be used in:
/arg1/&&/CLASS:/{print FILENAME ":" $0}'\
`find /mnt/p11/PhysicalSpace/DirTest -type f`
??
== TIA
[toc] | [prev] | [next] | [standalone]
| From | Bill Marcum <bill@lat.localnet> |
|---|---|
| Date | 2011-05-29 13:05 -0400 |
| Subject | Re: Re (2): HOW2 pass args to awk? |
| Message-ID | <slrniu4v7k.8kf.bill@lat.localnet> |
| In reply to | #1273 |
On 2011-05-29, no.top.post@gmail.com <no.top.post@gmail.com> wrote:
> In article <iqt74h$eqi$1@news.m-online.net>, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>
>> On 17.05.2011 08:27, no.top.post@gmail.com wrote:
>> > --
>> > I had suspected that ARGV could do it.
>> > But it fails. Are you fooling with me?
>>
>> No, certainly not. But unfortunately there's a problem on your end of the
>> communication channel; you are resistant to advice it seems. All necessary
>> information has been presented.
>>
>> In which ways does it fail? Show what you've done and we'll show you what
>> you've done wrong. Provide the necessary information; your environment,
>> your data, how you called it, your results, and the expected results.
>>
> Since you seem incapable of extracting the essence: HOW2 pass args to awk,
> which was repeatedly addressed by other writers, I give you the whole story.
>
> I want to have the location of files, in a special dir-tree, listed
> which have a line containing "CLASS:" and <argString> in the same
> line.
>
> Crrently I use the script - with no args:---
> #!/bin/bash
>
> awk '/Class:/&&/TLC/{print FILENAME}'\
> `find /mnt/p11/PhysicalSpace/DirTest -type f`
> ------------
> And I've got corresponding scripts for 'OCGE' & 'JK80K' ...etc. for
> several other strings besides "TLC".
>
> From my previous post, which you've snipped:
>> > gawk '
>> > BEGIN {
>> > arg1 = ARGV[1]
>> > arg2 = ARGV[2]
>> > print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised
>> > }'
>> >
>> > exit
>> > /arg1/&&/arg2/{print FILENAME ":" $0}'\
>> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
> isn't it obvious that if, at the line indicated the arg1 has not
> been 'extracted', that the guts of the routine [below `exit`]
> will fail TO DO WHAT I INTEND?
>
> The output of: ./<theScript> dog
> is: 'arg1='
>
>
> How would you, confirm that 'arg1', which has been passed to the script
> as the first arg, has been 'extracted', to be used in:
> /arg1/&&/CLASS:/{print FILENAME ":" $0}'\
> `find /mnt/p11/PhysicalSpace/DirTest -type f`
> ??
> == TIA
>
To pass arguments to gawk, they must be on the gawk "command line" (although
it's several lines long) after the }'.
Another thing: Whatever is inside / / is treated as a regular expression,
not a variable. To match input against the contents of a variable, use
$0 ~ arg1
--
Linux and Windows both win.
Best Documentary Feature: March of the Penguins
Best Picture: Crash
[toc] | [prev] | [next] | [standalone]
| From | no.top.post@gmail.com |
|---|---|
| Date | 2011-05-30 02:22 +0000 |
| Subject | Re (3): HOW2 pass args to awk? |
| Message-ID | <iruv18$46t$1@dont-email.me> |
| In reply to | #1274 |
In article <slrniu4v7k.8kf.bill@lat.localnet>, Bill Marcum <bill@lat.localnet> wrote:
> On 2011-05-29, no.top.post@gmail.com <no.top.post@gmail.com> wrote:
> > In article <iqt74h$eqi$1@news.m-online.net>, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> >
> >> On 17.05.2011 08:27, no.top.post@gmail.com wrote:
> >> > --
> >> > I had suspected that ARGV could do it.
> >> > But it fails. Are you fooling with me?
> >>
> >> No, certainly not. But unfortunately there's a problem on your end of the
> >> communication channel; you are resistant to advice it seems. All necessary
> >> information has been presented.
> >>
> >> In which ways does it fail? Show what you've done and we'll show you what
> >> you've done wrong. Provide the necessary information; your environment,
> >> your data, how you called it, your results, and the expected results.
> >>
> > Since you seem incapable of extracting the essence: HOW2 pass args to awk,
> > which was repeatedly addressed by other writers, I give you the whole story.
> >
> > I want to have the location of files, in a special dir-tree, listed
> > which have a line containing "CLASS:" and <argString> in the same
> > line.
> >
> > Crrently I use the script - with no args:---
> > #!/bin/bash
> >
> > awk '/Class:/&&/TLC/{print FILENAME}'\
> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
> > ------------
> > And I've got corresponding scripts for 'OCGE' & 'JK80K' ...etc. for
> > several other strings besides "TLC".
> >
> > From my previous post, which you've snipped:
> >> > gawk '
> >> > BEGIN {
> >> > arg1 = ARGV[1]
> >> > arg2 = ARGV[2]
> >> > print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised
> >> > }'
> >> >
> >> > exit
> >> > /arg1/&&/arg2/{print FILENAME ":" $0}'\
> >> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
> > isn't it obvious that if, at the line indicated the arg1 has not
> > been 'extracted', that the guts of the routine [below `exit`]
> > will fail TO DO WHAT I INTEND?
> >
> > The output of: ./<theScript> dog
> > is: 'arg1='
> >
> >
> > How would you, confirm that 'arg1', which has been passed to the script
> > as the first arg, has been 'extracted', to be used in:
> > /arg1/&&/CLASS:/{print FILENAME ":" $0}'\
> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
> > ??
> > == TIA
---------------------
> To pass arguments to gawk, they must be on the gawk "command line"
> (although it's several lines long) after the }'.
Why don't you WRITE the 'correction' ?!
> Another thing: Whatever is inside / / is treated as a
> regular expression, not a variable.
>
If the regex can't include an variable that has been 'set by the argument
which was passed to the script' then my goal can't be achieved.
> To match input against the contents of a variable, use
> $0 ~ arg1
Answer MY question. Not YOUR pet syntax.
Wouldn't "$0 ~ arg1" mean "the-record/line not-equal-arg1.
You awk-clowns are obviously fooling me or on narcotics.
My original question has raised two others:
1. the choice of the 2 proposed syntaxes:
i) arg1 = ARGV[1]
ii) -v c1="arg1"
2. the massive description in the cited FAQ, which specifically
addresses my question, and indicates that <awk is out of control>.
Why can't you answer MY questions, instead of side issues.
== TIA.
[toc] | [prev] | [next] | [standalone]
| From | Aragorn <aragorn@chatfactory.invalid> |
|---|---|
| Date | 2011-05-30 05:09 +0200 |
| Subject | Re: Re (3): HOW2 pass args to awk? |
| Message-ID | <irv1pf$sbc$2@dont-email.me> |
| In reply to | #1279 |
On Monday 30 May 2011 04:22 in comp.os.linux.misc, somebody identifying
as no.top.post@gmail.com wrote...
> In article <slrniu4v7k.8kf.bill@lat.localnet>, Bill Marcum
> <bill@lat.localnet> wrote:
>
>> On 2011-05-29, no.top.post@gmail.com <no.top.post@gmail.com> wrote:
>>
>> > In article <iqt74h$eqi$1@news.m-online.net>, Janis Papanagnou
>> > <janis_papanagnou@hotmail.com> wrote:
>> >
>> >> On 17.05.2011 08:27, no.top.post@gmail.com wrote:
>> >>
>> >> > I had suspected that ARGV could do it.
>> >> > But it fails. Are you fooling with me?
^^^^^^^^^^^^^^^^^^^^^^^
That's one...
>> >> [...]
>> >> In which ways does it fail? Show what you've done and we'll show
>> >> you what you've done wrong. Provide the necessary information;
>> >> your environment, your data, how you called it, your results, and
>> >> the expected results.
>> >>
>> > Since you seem incapable of extracting the essence: [...]
That's two...
>> To pass arguments to gawk, they must be on the gawk "command line"
>> (although it's several lines long) after the }'.
>
> Why don't you WRITE the 'correction' ?!
That's three...
>> [...]
>> To match input against the contents of a variable, use
>> $0 ~ arg1
>
> Answer MY question. Not YOUR pet syntax. [...]
That's three...
> Wouldn't "$0 ~ arg1" mean "the-record/line not-equal-arg1.
> You awk-clowns are obviously fooling me or on narcotics.
That's four...
> [...]
>
> Why can't you answer MY questions, instead of side issues.
And that's five. I'm not exactly an awk specialist, but I've seen you
post to comp.os.linux.misc for a few years already, and I can well
remember dozens of other samples of your questionable behavior on
Usenet.
You, Sir, are rude, ill-mannered, selfish and utterly ungrateful towards
the people who are helping you with your homework assignments. And
that is why I shall be redirecting your posts to "/dev/null" from here
on.
<plonk>
--
*Aragorn*
(registered GNU/Linux user #223157)
[toc] | [prev] | [next] | [standalone]
| From | Bill Marcum <bill@lat.localnet> |
|---|---|
| Date | 2011-05-17 07:55 -0400 |
| Message-ID | <slrnit4oho.5u2.bill@lat.localnet> |
| In reply to | #1123 |
["Followup-To:" header set to comp.os.linux.misc.]
On 2011-05-17, no.top.post@gmail.com <no.top.post@gmail.com> wrote:
> I had suspected that ARGV could do it.
> But it fails. Are you fooling with me?
> gawk '
> BEGIN {
> arg1 = ARGV[1]
> arg2 = ARGV[2]
> print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised
> }'
>
> exit
> /arg1/&&/arg2/{print FILENAME ":" $0}'\
> `find /mnt/p11/PhysicalSpace/DirTest -type f`
>
In the above script, the gawk command ends at }' . It has no
arguments. "exit" is interpreted as a shell command, and the lines
after it are ignored.
--
"Remember when teachers, public employees, Planned Parenthood, NPR and PBS
crashed the stock market, wiped out half of our 401Ks, took trillions in
TARP money, spilled oil in the Gulf of Mexico, gave themselves billions in
bonuses, and paid no taxes? Yeah, me neither."
[toc] | [prev] | [next] | [standalone]
| From | no.top.post@gmail.com |
|---|---|
| Date | 2011-05-29 15:56 +0000 |
| Subject | Re (2): HOW2 pass args to awk? |
| Message-ID | <irtqbk$9ka$1@dont-email.me> |
| In reply to | #1131 |
In article <slrnit4oho.5u2.bill@lat.localnet>, Bill Marcum <bill@lat.localnet> wrote:
> ["Followup-To:" header set to comp.os.linux.misc.]
> On 2011-05-17, no.top.post@gmail.com <no.top.post@gmail.com> wrote:
> > I had suspected that ARGV could do it.
> > But it fails. Are you fooling with me?
> > gawk '
> > BEGIN {
> > arg1 = ARGV[1]
> > arg2 = ARGV[2]
> > print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised
> > }'
> >
> > exit
> > /arg1/&&/arg2/{print FILENAME ":" $0}'\
> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
> >
> In the above script, the gawk command ends at }' . It has no
> arguments. "exit" is interpreted as a shell command, and the lines
> after it are ignored.
Yes that's how I intended, except that IT is a script and gets
CALLED WITH ARGS. So I want to call the script with 2 args:
`script dog fish`
and confirm that `print "arg1=" arg1` has got 'dog'.
Isn't it obvious that I've pasted my actual script, that I've been
hacking ?
The output of: ./<theScript> dog
is: 'arg1='
So would that pass 'dog' to the <awk operation> as required ?
== TIA
PS I'm posting from the 3rd world & can only post on weekends.
[toc] | [prev] | [next] | [standalone]
| From | Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> |
|---|---|
| Date | 2011-05-29 17:46 +0000 |
| Subject | Re: Re (2): HOW2 pass args to awk? |
| Message-ID | <pan.2011.05.29.17.46.08@thedarkdesign.free.fr.INVALID> |
| In reply to | #1272 |
Sun, 29 May 2011 15:56:37 +0000, no.top.post did cat :
> In article <slrnit4oho.5u2.bill@lat.localnet>, Bill Marcum
> <bill@lat.localnet> wrote:
>
>> ["Followup-To:" header set to comp.os.linux.misc.] On 2011-05-17,
>> no.top.post@gmail.com <no.top.post@gmail.com> wrote:
>> > I had suspected that ARGV could do it. But it fails. Are you fooling
>> > with me?
>> > gawk '
>> > BEGIN {
>> > arg1 = ARGV[1]
>> > arg2 = ARGV[2]
>> > print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised }'
>> >
>> > exit
>> > /arg1/&&/arg2/{print FILENAME ":" $0}'\
>> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
>> >
>> In the above script, the gawk command ends at }' . It has no
>> arguments. "exit" is interpreted as a shell command, and the lines
>> after it are ignored.
> Yes that's how I intended, except that IT is a script and gets CALLED
> WITH ARGS. So I want to call the script with 2 args:
> `script dog fish`
> and confirm that `print "arg1=" arg1` has got 'dog'.
>
> Isn't it obvious that I've pasted my actual script, that I've been
> hacking ?
>
> The output of: ./<theScript> dog
> is: 'arg1='
>
> So would that pass 'dog' to the <awk operation> as required ?
>
> == TIA
>
> PS I'm posting from the 3rd world & can only post on weekends.
Understood, some local production to test sure can make
some difficult awakenings
Still not sure of what you exactly mean to actually do but I think
that I now have an idea of what you're trying and write in your posts
so here's a short test on sample files that may help you and the group to
find a common language platform, at least if you can say and explain
if (and why) it is not what you want ;-)
I started with a "mother" file:
---------
$ cat animalz
Class: dog fish cow
Class: cow mouse
Class: flea market
Order: flea dog
Order: mouse dog
Class: fly dog
Class: flea dog
Order: cow dog
Noise: blurb doubt
---------
and made a bunch of bench files from it:
---------
$ split -l 1 animalz
---------
So, if that bench is not related to your question please then tell how
and, better yet, provide a short bench env.
If the bench is "admissible", then this could well represent a
starting track for an answer to your question :-)
---------
$ find . -type f -name 'x*' | xargs awk -v arg1="Class:" -v arg2="cow" -v arg3="mouse" '($0~arg1 && ( $0~arg2 || $0~arg3)){print FILENAME,FNR,$0}'
./xab 1 Class: cow mouse
./xaa 1 Class: dog fish cow
---------
[toc] | [prev] | [next] | [standalone]
| From | no.top.post@gmail.com |
|---|---|
| Date | 2011-05-30 02:22 +0000 |
| Subject | Re (3): HOW2 pass args to awk? |
| Message-ID | <iruv09$40j$1@dont-email.me> |
| In reply to | #1275 |
In article <pan.2011.05.29.17.46.08@thedarkdesign.free.fr.INVALID>, Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> wrote:
> Sun, 29 May 2011 15:56:37 +0000, no.top.post did cat :
>
> > In article <slrnit4oho.5u2.bill@lat.localnet>, Bill Marcum
> > <bill@lat.localnet> wrote:
> >
> >> ["Followup-To:" header set to comp.os.linux.misc.] On 2011-05-17,
> >> no.top.post@gmail.com <no.top.post@gmail.com> wrote:
> >> > I had suspected that ARGV could do it. But it fails. Are you fooling
> >> > with me?
> >> > gawk '
> >> > BEGIN {
> >> > arg1 = ARGV[1]
> >> > arg2 = ARGV[2]
> >> > print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised }'
> >> >
> >> > exit
> >> > /arg1/&&/arg2/{print FILENAME ":" $0}'\
> >> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
> >> >
---------------
Why don't you comment on my obvious attempt to TRACE
the <arg to the script> as being [or NOT] allocated to 'arg1',
instead of going off on your own, prefered syntax?!
--------------------
> >> In the above script, the gawk command ends at }' . It has no
> >> arguments. "exit" is interpreted as a shell command, and the lines
> >> after it are ignored.
> > Yes that's how I intended, except that IT is a script and gets CALLED
> > WITH ARGS. So I want to call the script with 2 args:
> > `script dog fish`
> > and confirm that `print "arg1=" arg1` has got 'dog'.
> >
> > Isn't it obvious that I've pasted my actual script, that I've been
> > hacking ?
> >
> > The output of: ./<theScript> dog
> > is: 'arg1='
> >
> > So would that pass 'dog' to the <awk operation> as required ?
> >
> > == TIA
> >
> > PS I'm posting from the 3rd world & can only post on weekends.
>
> Understood, some local production to test sure can make
> some difficult awakenings
>
> Still not sure of what you exactly mean to actually do but I think
> that I now have an idea of what you're trying and write in your posts
> so here's a short test on sample files that may help you and the group to
> find a common language platform, at least if you can say and explain
> if (and why) it is not what you want ;-)
>
> I started with a "mother" file:
> ---------
> $ cat animalz
> Class: dog fish cow
> Class: cow mouse
> Class: flea market
> Order: flea dog
> Order: mouse dog
> Class: fly dog
> Class: flea dog
> Order: cow dog
>
> Noise: blurb doubt
> ---------
>
> and made a bunch of bench files from it:
> ---------
> $ split -l 1 animalz
> ---------
>
> So, if that bench is not related to your question please then
> tell how and, better yet, provide a short bench env.
>
> If the bench is "admissible", then this could well represent a
> starting track for an answer to your question :-)
No! My question is "HOW2 pass args to awk?" !!
It is inappropriate to change the format of the rest of the script,
to your prefered style.
We know there are countless styles which will achieve the goal.
Please comment on the previously suggested syntax of
arg1 = ARGV[1]
It seems that there are 2 candidate syntaxes, and every clown
is pushing HIS favourite.
Did YOU understand my attempt to TRACE the successful
conversion of the <arg passed to the script>, inside the script,
before it's used in the regex-matching?
Is that unsound ?
Do YOU realise that I want to call a script with [initially]
one arg. Currently I just call different scripts for each <class>.
This 'project' is amazingly simple, yet massively powerfull,
to help <find the real-space-location of your paper docus,
since the dir-tree is perfectly isomorphic to real-space.
> ---------
> $ find . -type f -name 'x*' | \
> xargs awk -v arg1="Class:" \
> -v arg2="cow" -v arg3="mouse"\
> '($0~arg1 && ( $0~arg2 || $0~arg3))\
> {print FILENAME,FNR,$0}'
>
> ../xab 1 Class: cow mouse
> ../xaa 1 Class: dog fish cow
> ---------
> .
Do you realise that my 'code' is in a bash-script ?
==TIA.
[toc] | [prev] | [next] | [standalone]
| From | Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> |
|---|---|
| Date | 2011-05-30 09:01 +0000 |
| Subject | Re: Re (3): HOW2 pass args to awk? |
| Message-ID | <pan.2011.05.30.09.01.34@thedarkdesign.free.fr.INVALID> |
| In reply to | #1278 |
Mon, 30 May 2011 02:22:06 +0000, no.top.post did cat :
> In article <pan.2011.05.29.17.46.08@thedarkdesign.free.fr.INVALID>, Loki
> Harfagr <l0k1@thedarkdesign.free.fr.INVALID> wrote:
>
>> Sun, 29 May 2011 15:56:37 +0000, no.top.post did cat :
>>
>> > In article <slrnit4oho.5u2.bill@lat.localnet>, Bill Marcum
>> > <bill@lat.localnet> wrote:
>> >
>> >> ["Followup-To:" header set to comp.os.linux.misc.] On 2011-05-17,
>> >> no.top.post@gmail.com <no.top.post@gmail.com> wrote:
>> >> > I had suspected that ARGV could do it. But it fails. Are you
>> >> > fooling with me?
>> >> > gawk '
>> >> > BEGIN {
>> >> > arg1 = ARGV[1]
>> >> > arg2 = ARGV[2]
>> >> > print "arg1=" arg1 <--- 'arg1' is 'empty'/uninitialised }'
>> >> >
>> >> > exit
>> >> > /arg1/&&/arg2/{print FILENAME ":" $0}'\
>> >> > `find /mnt/p11/PhysicalSpace/DirTest -type f`
>> >> >
> ---------------
> Why don't you comment on my obvious attempt to TRACE the <arg to the
> script> as being [or NOT] allocated to 'arg1', instead of going off on
> your own, prefered syntax?! --------------------
I'm not "going off on your own, prefered syntax", I was just trying to
help you and us to reach a point where what you post would be readable and
understandable (On a technical point of view that is, I won't try and
do anything about your Tourette and the dried mushrooms).
So, the answer to that question:
" Why don't you comment on my obvious attempt to TRACE the <arg
...
"
is that I wouldn't comment something that was not obvious at all to
me as I really couldn't find a reason why you posted that snippet of
non code coming out from the blue and going nowhere.
>> >> In the above script, the gawk command ends at }' . It has no
>> >> arguments. "exit" is interpreted as a shell command, and the lines
>> >> after it are ignored.
>> > Yes that's how I intended, except that IT is a script and gets CALLED
>> > WITH ARGS. So I want to call the script with 2 args:
>> > `script dog fish`
>> > and confirm that `print "arg1=" arg1` has got 'dog'.
>> >
>> > Isn't it obvious that I've pasted my actual script, that I've been
>> > hacking ?
>> >
>> > The output of: ./<theScript> dog
>> > is: 'arg1='
>> >
>> > So would that pass 'dog' to the <awk operation> as required ?
>> >
>> > == TIA
>> >
>> > PS I'm posting from the 3rd world & can only post on weekends.
>>
>> Understood, some local production to test sure can make some difficult
>> awakenings
>>
>> Still not sure of what you exactly mean to actually do but I think that
>> I now have an idea of what you're trying and write in your posts so
>> here's a short test on sample files that may help you and the group to
>> find a common language platform, at least if you can say and explain if
>> (and why) it is not what you want ;-)
>>
>> I started with a "mother" file:
>> ---------
>> $ cat animalz
>> Class: dog fish cow
>> Class: cow mouse
>> Class: flea market
>> Order: flea dog
>> Order: mouse dog
>> Class: fly dog
>> Class: flea dog
>> Order: cow dog
>>
>> Noise: blurb doubt
>> ---------
>>
>> and made a bunch of bench files from it: ---------
>> $ split -l 1 animalz
>> ---------
>>
>> So, if that bench is not related to your question please then tell how
>> and, better yet, provide a short bench env.
>>
>> If the bench is "admissible", then this could well represent a starting
>> track for an answer to your question :-)
> No! My question is "HOW2 pass args to awk?" !!
That's the part of your initial post that was quite understandable, since
then you had several various answers, including a few about the ARGV stuff
and, though I thought theses answers addressed your question you then started
roaring like a Vulcan forcefed with powerpoint presentations.
So I supposed you still had a problem with your "search script" and I
simply asked if your question could be simplified and exampled on a very
small set of bench stuff and hence proposed a first version of
bench that you would "admit" or "extend" or propose a better one.
The question until now, for me, is that you're requesting every one to
use some specific words in some sentences in order to write a paragraph
but I just suggested that we all start with being in tune about what the
final paragraph would express.
> It is inappropriate to
> change the format of the rest of the script, to your prefered style.
> We know there are countless styles which will achieve the goal. Please
> comment on the previously suggested syntax of
> arg1 = ARGV[1]
I'd say others already have done so, and as for myself I won't comment
about the style on an operation that I have no idea what its goal is.
You may have some reasons to insist on using a corkscrew to file this
nail but at this point I still don't understand what are all these
spoons for and where do they joint with the yellow turtle in the middle
of the rack.
> It seems that there are 2 candidate syntaxes, and every clown is pushing
> HIS favourite.
> Did YOU understand my attempt to TRACE the successful conversion of the
> <arg passed to the script>, inside the script, before it's used in the
> regex-matching?
No, first I didn't recognize that you were attempting that and then
I still have no idea about (see supra...)
> Is that unsound ?
> Do YOU realise that I want to call a script with [initially] one arg.
No. Nor any idea where I would have found that hint, but I may have
missed it somewhere in the tons of strange snippets ;-)
> Currently I just call different scripts for each <class>. This 'project'
> is amazingly simple, yet massively powerfull, to help <find the
> real-space-location of your paper docus, since the dir-tree is perfectly
> isomorphic to real-space.
>> ---------
>> $ find . -type f -name 'x*' | \
>> xargs awk -v arg1="Class:" \
>> -v arg2="cow" -v arg3="mouse"\
>> '($0~arg1 && ( $0~arg2 || $0~arg3))\
>> {print FILENAME,FNR,$0}'
>>
>> ../xab 1 Class: cow mouse
>> ../xaa 1 Class: dog fish cow
>> ---------
>> .
> Do you realise that my 'code' is in a bash-script ?
well, do you realize that so is mine ? Or so could it?
It is called directly in a shell but a shell is a script is a rose
(to most extents at least, we'll avoid any extensive discussion on
environments at this point of the thread as it already is quite
painful enough to read)
>
> ==TIA.
So, from the tiny bench I proposed are we going somewhere?
Is that close enough to you problem? If not could you post a
bench that would be usable and understandable enough that would do
the stuff you want and then the group could concentrate to
understand enough your question and your addressing so we'll
have a chance to try any complementary answer about style/args/whatever.
[toc] | [prev] | [next] | [standalone]
| From | Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> |
|---|---|
| Date | 2011-05-31 11:05 +0000 |
| Subject | Re: Re (3): HOW2 pass args to awk? and more |
| Message-ID | <4de4cb6c$0$17785$426a34cc@news.free.fr> |
| In reply to | #1278 |
Mon, 30 May 2011 02:22:06 +0000, no.top.post did cat :
while browsing the groups I saw you topic line again and I
just wondered if your supposedly firm question
> No! My question is "HOW2 pass args to awk?" !!
wouldn't actually be:
"How to pass the wrapper script command line arguments to the inner encapsulated awk script"
like:
--------
$ cat doh
#!/bin/bash
###
printf "In script: 1,2,3==$1,$2,$3\n"
###
awk 'BEGIN {
arg1 = ARGV[1]
arg2 = ARGV[2]
arg3 = ARGV[3]
print "arg1=" arg1
print "arg2=" arg2
print "arg3=" arg3
}
' $1 $2 $3
--------
--------
$ ./doh cat dog rain
In script: 1,2,3==cat,dog,rain
arg1=cat
arg2=dog
arg3=rain
--------
[toc] | [prev] | [next] | [standalone]
| From | Ralf Fassel <ralfixx@gmx.de> |
|---|---|
| Date | 2011-05-31 14:35 +0200 |
| Subject | Re: Re (3): HOW2 pass args to awk? and more |
| Message-ID | <yga1uzfrqso.fsf@gepard2.akutech-local.de> |
| In reply to | #1289 |
* Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID>
| awk 'BEGIN {
| arg1 = ARGV[1]
| arg2 = ARGV[2]
| arg3 = ARGV[3]
| print "arg1=" arg1
| print "arg2=" arg2
| print "arg3=" arg3
| }
| ' $1 $2 $3
This will only work if you don't do any work in the awk script. The $1
$2 $3 in that place on the awk command line will be interpreted by awk
as filenames to read.
To pass values to awk, use the -v switch.
$ cat script
#!/bin/sh
printf "In script: 1,2,3==$1,$2,$3\n"
awk -v arg1=$1 -v arg2=$2 'BEGIN { print arg1, arg2 }'
$ ./script foo bar
In script: 1,2,3==dog,cat,rain
dog cat
R'
[toc] | [prev] | [next] | [standalone]
| From | Ed Morton <mortonspam@gmail.com> |
|---|---|
| Date | 2011-05-31 07:56 -0500 |
| Subject | Re: Re (3): HOW2 pass args to awk? and more |
| Message-ID | <is2oh6$ge4$1@dont-email.me> |
| In reply to | #1290 |
On 5/31/2011 7:35 AM, Ralf Fassel wrote:
> * Loki Harfagr<l0k1@thedarkdesign.free.fr.INVALID>
> | awk 'BEGIN {
> | arg1 = ARGV[1]
> | arg2 = ARGV[2]
> | arg3 = ARGV[3]
> | print "arg1=" arg1
> | print "arg2=" arg2
> | print "arg3=" arg3
> | }
> | ' $1 $2 $3
>
> This will only work if you don't do any work in the awk script.
I assume you mean do any work in the body of the script as opposed to the BEGIN
section, which is not the case in the above script. Tha main problem I see with
the above is that it doesn't quote the shell positional parameters so if they
contain spaces you'll get undesirable results.
The $1
> $2 $3 in that place on the awk command line will be interpreted by awk
> as filenames to read.
Only if you write a script with more than a BEGIN section and you forget to
delete those arguments before leaving the BEGIN section.
>
> To pass values to awk, use the -v switch.
>
> $ cat script
> #!/bin/sh
> printf "In script: 1,2,3==$1,$2,$3\n"
> awk -v arg1=$1 -v arg2=$2 'BEGIN { print arg1, arg2 }'
> $ ./script foo bar
> In script: 1,2,3==dog,cat,rain
> dog cat
>
> R'
In general you're right to recommend "-v" but it's not _always_ the right
option, depending on how you want a couple of conditions handled, so it's good
to point people to the FAQ:
http://cfajohnson.com/shell/cus-faq-2.html#Q24
Regards,
Ed.
[toc] | [prev] | [next] | [standalone]
| From | Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> |
|---|---|
| Date | 2011-05-31 14:14 +0000 |
| Subject | Re: Re (3): HOW2 pass args to awk? and more |
| Message-ID | <4de4f7c5$0$20052$426a34cc@news.free.fr> |
| In reply to | #1290 |
Tue, 31 May 2011 14:35:35 +0200, Ralf Fassel did cat :
> * Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> | awk 'BEGIN {
> | arg1 = ARGV[1]
> | arg2 = ARGV[2]
> | arg3 = ARGV[3]
> | print "arg1=" arg1
> | print "arg2=" arg2
> | print "arg3=" arg3
> | }
> | ' $1 $2 $3
>
> This will only work if you don't do any work in the awk script. The $1
> $2 $3 in that place on the awk command line will be interpreted by awk
> as filenames to read.
Well, yes, of course I'd agree if that script was a real script :-)
The snippet of script was only a PoC for the OP
(please read the full thread if you really wanna know)
>
> To pass values to awk, use the -v switch.
OMG, Noooooo get baaaack !-D)
this was already proposed several times in the thread and
rebuked several times by the OP so I suppose he would do so again ,-)
and, well... please read the full thread if you really wanna know :D)
(but you'll have to find the various bits of he thread as the
OP scattered it quite energically ;-)
>
> $ cat script
> #!/bin/sh
> printf "In script: 1,2,3==$1,$2,$3\n" awk -v arg1=$1 -v arg2=$2 'BEGIN
> { print arg1, arg2 }' $ ./script foo bar
> In script: 1,2,3==dog,cat,rain
> dog cat
>
> R'
[toc] | [prev] | [next] | [standalone]
| From | Ralf Fassel <ralfixx@gmx.de> |
|---|---|
| Date | 2011-06-01 10:41 +0200 |
| Subject | Re: Re (3): HOW2 pass args to awk? and more |
| Message-ID | <ygawrh6q6yt.fsf@gepard2.akutech-local.de> |
| In reply to | #1294 |
* Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> | > To pass values to awk, use the -v switch. > | OMG, Noooooo get baaaack !-D) I knew I had the vague impression something was wrong with this thread :-), especially when Ed in the other message <is2oh6$ge4$1@dont-email.me> posted the URL to the exact answer to the question in the cus-FAQ... R', EOT4me
[toc] | [prev] | [next] | [standalone]
| From | no.top.post@gmail.com |
|---|---|
| Date | 2011-06-06 10:26 +0000 |
| Subject | Re (4): HOW2 pass args to awk? and more |
| Message-ID | <isi9vr$pns$1@dont-email.me> |
| In reply to | #1290 |
In article <yga1uzfrqso.fsf@gepard2.akutech-local.de>, Ralf Fassel <ralfixx@gmx.de> wrote:
> * Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID>
> | awk 'BEGIN {
> | arg1 = ARGV[1]
> | arg2 = ARGV[2]
> | arg3 = ARGV[3]
> | print "arg1=" arg1
> | print "arg2=" arg2
> | print "arg3=" arg3
> | }
> | ' $1 $2 $3
>
> This will only work if you don't do any work in the awk script.
> The $1 $2 $3 in that place on the awk command line
> will be interpreted by awk as filenames to read.
OK, that answers a previous question.
And will they be the 3 args passed to the script
which contains the `awk job` ?
Apparently not.
> To pass values to awk, use the -v switch.
>
> $ cat script
> #!/bin/sh
> printf "In script: 1,2,3==$1,$2,$3\n"
> awk -v arg1=$1 -v arg2=$2 'BEGIN { print arg1, arg2 }'
> $ ./script foo bar
> In script: 1,2,3==dog,cat,rain
> dog cat
>
Understandably, I get:--
./script foo bar
In script: 1,2,3==foo,bar,
foo bar
And further ----> script2 ==
#!/bin/sh
printf "In script: 1,2,3==$1,$2,$3\n"
awk -v arg1=$1 -v arg2=$2 'BEGIN { print arg1, arg2 }'
echo 'In script after exit awk, args 1,2,3==' $1,$2,$3
--> ./script2 foo bar ==
In script: 1,2,3==foo,bar,
foo bar
In script after exit awk, args 1,2,3== foo,bar,
------------------
>> This will only work if you don't do any work in the awk script.
Ed Morton wrote:-
> I assume you mean do any work in the body of the script as opposed
> to the BEGIN section, which is not the case in the above script.
> Tha main problem I see with the above is that it doesn't quote the
> shell positional parameters so if they contain spaces you'll get
> undesirable results.
>
> > The $1 $2 $3 in that place on the awk command line
> > will be interpreted by awk as filenames to read.
>
> Only if you write a script with more than a BEGIN section and you
> forget to delete those arguments before leaving the BEGIN section.
OMG what a crappy-convoluted finite-state-machine is awk?
> In general you're right to recommend "-v" but it's not _always_ the
> right option, depending on how you want a couple of conditions
> handled, so it's good to point people to the FAQ:
> http://cfajohnson.com/shell/cus-faq-2.html#Q24
Yes and reading faq-2.html#Q24 can lead to a
nervous-breakdown.
--------
Loki Harfagr wrote:-
> Well, yes, of course I'd agree if that script was a real script :-)
So, write YOUR 'real script' to:
list all files in ./
which contain ON THE SAME LINE,
the strings "Class:" and <stringArg1>.
So that: ./<ScriptName> dog
will list all files which contain lines like:-
Class: mouse dog fish no need for ...
----------
Then extend it to find <dog and mouse>.
Then extend it to find (dog AND mouse) OR (dog and cow).
-----------
The awk/grep stuff is trivial compared to the profoundness
of the application, as seen by the following scenario:-
You've got some filing-cabinets and boxes with important docus.
Tomorrow you're going to a meeting, related to dog, cow, fish.
?SOMEHOW? you collect a dozen docus with are relevant, and
put them in your <box for meetingX>.
BTW, where/how did you 'file' docus which relate to <dog AND fish> ?
At the meeting, it's decided because of an unanticipated event,
that the bussiness must be concluded, next Thursday.
When you get <back-home> are you going to refile the docus,
or leave them in the box till next Thursday?
How do you know where the <dog AND fish> docu was filed?
If you leave the docus in <box for meetingX+Thursday>, and you
have a unexpected-event/crisis, so as to need to miss the next
meeting, how would you know after 2 months, what/where's in
the box?
Apparently the normal [pre-computerised] method is to
search&sort. With computerisation we can 'index'.
Let each docu KNOW 'where it is in real-space'.
This is facilitated by the lucky fact that 'real-space is perfectly
isomorphic to a dir-sub-tree'. Ie. each docu corresponds to a
file/leaf-node of the dir-sub-tree.
So the awk/grep script must give a list of <path/files> like:
/Ofic2/Cabnt5/Draw1/HfileDog/History
/Concertina/Sectn/M/meds
And perhaps the 'meds' file, has a line:-
Class: dog cow fish ...
...etc. you get it ?
Now here's the real POWER.
When you move the phyical paper-docu from a location into
<box for meetingX>, you use `mc` [which VISUALLY with hot-keys]
easily allows you to:
* create the sub-dir for the <box for meetingX>.
* move single-files or a whole container/sub-dir if files to
a new location.
NB real paper-files in real-space correspond to
linux-dir-files in the [isomorphic to real space] dir-tree.
So now you just need the computer to search the corrsponding
dir-tree to locate the relevant docus. -- QED.
------------
An extra bonus comes from `mc`:-
When it show you a list of a dozen files re. <dog OR fish>,
you just scroll down to <an interesting one> and
hit <F3> to view/read inside the file, or
hit <F4> if you want to eg. make/edit same extra notes,
re. <next Thursdays meeting or what ever>.
BTW you do see that, when you move the concertina-file
[which has 26 pockets] from officeA to officeD, you just
move the corresponding dir-node [via <F6>] with `mc`,
and the computer KNOWS where all the docus in the
concertina file are located in real-space.
------
A further easy extention which is useful, after you've got
the file-list for <Class: dog AND cow> is to grep in the
file-list for files which contain <keyword/s>
So ideally, you'd want to pass these various args to the script/s.
Presently I use different scripts, and it works OK.
If it's not easy/convenient, you will tend to by-pass it and your
docus will degenerate into chaos.
The missing part of the system is the portable computer:
so that when you physically move the paper-docus, you can
immediately, make the corresponding computer change,
with out moving yourself from the paper-location to
the computer-location.
== Chris Glur.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.os.linux.misc
csiph-web