zsh-users
 help / color / mirror / code / Atom feed
* Scripting situation I cannot wrap my head around
@ 2006-12-05  7:31 TjL
       [not found] ` <237967ef0612050017y1816e7fs66a3bdac8337fac3@mail.gmail.com>
  2006-12-05 15:40 ` Jean-Rene David
  0 siblings, 2 replies; 6+ messages in thread
From: TjL @ 2006-12-05  7:31 UTC (permalink / raw)
  To: Zsh Users List

My apologies for asking you all for what feels like a basic question,
but I am missing something and cannot wrap my head around how to fix
it.

I am currently writing "verbatims" for a class that I am taking.  The
teacher wants the verbatims to include a number for each time a person
has spoken.

An example will make this more clear.  Assume that John, Tim and
George and talking.

Here is "normal" dialog:

John: How are you today?
Tim: I'm good.
George: I'm Ok, how are you
John: I'm good too.
George: Glad to hear it
John: Thanks
Tim: Yeah, me too

Here is verbatim style dialog:

John1: How are you today?
Tim1: I'm good.
George1: I'm Ok, how are you
John2: I'm good too.
George2: Glad to hear it
John3: Thanks
Tim2: Yeah, me too

Notice that the number next to the name represents the number of times
that person has said something (it doesn't matter WHO they said it
to).

What I am trying to do is figure out a way to have the numbering done
for me, but I can't wrap my head around how to do that.  You would
need separate counters for each person, and you wouldn't know how many
people would be a part of the conversation (no fewer than 2 people,
probably no more than 10, usually 2-5).

I've tried to come up with WHILE loops or FOR loops using counters and
such, but I can't get past the first hurdle, which seems to be: how to
keep track of a counter for each speaker when you don't know how many
speakers you will have.

Any help appreciated.  The fact that it's 2:30am may have something to
do with my brain fog (I hope!) so my apologies if I am missing
something obvious!

TjL


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Scripting situation I cannot wrap my head around
       [not found] ` <237967ef0612050017y1816e7fs66a3bdac8337fac3@mail.gmail.com>
@ 2006-12-05  8:18   ` Mikael Magnusson
  2006-12-05 14:35     ` Torur Andreassen
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2006-12-05  8:18 UTC (permalink / raw)
  To: zsh-users

On 05/12/06, TjL <luomat@gmail.com> wrote:
> My apologies for asking you all for what feels like a basic question,
> but I am missing something and cannot wrap my head around how to fix
> it.
>
> I am currently writing "verbatims" for a class that I am taking.  The
> teacher wants the verbatims to include a number for each time a person
> has spoken.
>
> An example will make this more clear.  Assume that John, Tim and
> George and talking.
>
> Here is "normal" dialog:
>
> John: How are you today?
> Tim: I'm good.
> George: I'm Ok, how are you
> John: I'm good too.
> George: Glad to hear it
> John: Thanks
> Tim: Yeah, me too
>
> Here is verbatim style dialog:
>
> John1: How are you today?
> Tim1: I'm good.
> George1: I'm Ok, how are you
> John2: I'm good too.
> George2: Glad to hear it
> John3: Thanks
> Tim2: Yeah, me too
>
> Notice that the number next to the name represents the number of times
> that person has said something (it doesn't matter WHO they said it
> to).
>
> What I am trying to do is figure out a way to have the numbering done
> for me, but I can't wrap my head around how to do that.  You would
> need separate counters for each person, and you wouldn't know how many
> people would be a part of the conversation (no fewer than 2 people,
> probably no more than 10, usually 2-5).
>
> I've tried to come up with WHILE loops or FOR loops using counters and
> such, but I can't get past the first hurdle, which seems to be: how to
> keep track of a counter for each speaker when you don't know how many
> speakers you will have.
>
> Any help appreciated.  The fact that it's 2:30am may have something to
> do with my brain fog (I hope!) so my apologies if I am missing
> something obvious!
>
> TjL

Maybe this will help

% typeset -A verbatim
% verbatim[John]=1
% verbatim[Tim]=3
% echo $verbatim
3 1
% echo $verbatim[John]
1
% echo $verbatim[Tim]
3

--
Mikael Magnusson
ps forgot to hit reply to all, as usual


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Scripting situation I cannot wrap my head around
  2006-12-05  8:18   ` Mikael Magnusson
@ 2006-12-05 14:35     ` Torur Andreassen
  0 siblings, 0 replies; 6+ messages in thread
From: Torur Andreassen @ 2006-12-05 14:35 UTC (permalink / raw)
  To: zsh-users

On Tue, Dec 05, 2006 at 09:18:21AM +0100, Mikael Magnusson wrote:
> On 05/12/06, TjL <luomat@gmail.com> wrote:
> >My apologies for asking you all for what feels like a basic question,
> >but I am missing something and cannot wrap my head around how to fix
> >it.
> >
> >I am currently writing "verbatims" for a class that I am taking.  The
> >teacher wants the verbatims to include a number for each time a person
> >has spoken.
> >
> >An example will make this more clear.  Assume that John, Tim and
> >George and talking.
> >
> >Here is "normal" dialog:
> >
> >John: How are you today?
> >Tim: I'm good.
> >George: I'm Ok, how are you
> >John: I'm good too.
> >George: Glad to hear it
> >John: Thanks
> >Tim: Yeah, me too
> >
> >Here is verbatim style dialog:
> >
> >John1: How are you today?
> >Tim1: I'm good.
> >George1: I'm Ok, how are you
> >John2: I'm good too.
> >George2: Glad to hear it
> >John3: Thanks
> >Tim2: Yeah, me too
> >
> >Notice that the number next to the name represents the number of times
> >that person has said something (it doesn't matter WHO they said it
> >to).
> >
> >What I am trying to do is figure out a way to have the numbering done
> >for me, but I can't wrap my head around how to do that.  You would
> >need separate counters for each person, and you wouldn't know how many
> >people would be a part of the conversation (no fewer than 2 people,
> >probably no more than 10, usually 2-5).
> >
> >I've tried to come up with WHILE loops or FOR loops using counters and
> >such, but I can't get past the first hurdle, which seems to be: how to
> >keep track of a counter for each speaker when you don't know how many
> >speakers you will have.
> >
> >Any help appreciated.  The fact that it's 2:30am may have something to
> >do with my brain fog (I hope!) so my apologies if I am missing
> >something obvious!
> >
> >TjL
> 
> Maybe this will help
> 
> % typeset -A verbatim
> % verbatim[John]=1
> % verbatim[Tim]=3
> % echo $verbatim
> 3 1
> % echo $verbatim[John]
> 1
> % echo $verbatim[Tim]
> 3

This might also be useful:

% ((verbatim[John]++))
% echo $verbatim[John]
2

-- 
Thor Andreassen


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Scripting situation I cannot wrap my head around
  2006-12-05  7:31 Scripting situation I cannot wrap my head around TjL
       [not found] ` <237967ef0612050017y1816e7fs66a3bdac8337fac3@mail.gmail.com>
@ 2006-12-05 15:40 ` Jean-Rene David
  2006-12-05 23:43   ` Paul Johnson
  1 sibling, 1 reply; 6+ messages in thread
From: Jean-Rene David @ 2006-12-05 15:40 UTC (permalink / raw)
  To: Zsh Users List

* TjL [2006.12.05 07:15]:
> [...]
> I am currently writing "verbatims" for a class
> that I am taking.
> [...]
> Here is "normal" dialog:
> 
> John: How are you today?
> Tim: I'm good.
> George: I'm Ok, how are you
> John: I'm good too.
> George: Glad to hear it
> John: Thanks
> Tim: Yeah, me too
> 
> Here is verbatim style dialog:
> 
> John1: How are you today?
> Tim1: I'm good.
> George1: I'm Ok, how are you
> John2: I'm good too.
> George2: Glad to hear it
> John3: Thanks
> Tim2: Yeah, me too
> 
> [...] You would need separate counters for each
> person, and you wouldn't know how many people
> would be a part of the conversation (no fewer
> than 2 people, probably no more than 10, usually
> 2-5).

The 'separate counters for each person' sounds
like a hash to me, and was suggested by others.

However I think a text processing tool would be
more appropriate than a shell for this kind of
task:

% perl -ne 'BEGIN { %person=(); } \
          /^([a-zA-Z]+)(:)(.*)$/ &&  \
            print "$1" . ++$person{$1} . "$2$3\n";' < dialog.file

HTH,

-- 
JR


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Scripting situation I cannot wrap my head around
  2006-12-05 15:40 ` Jean-Rene David
@ 2006-12-05 23:43   ` Paul Johnson
  2006-12-06 19:34     ` TjL
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Johnson @ 2006-12-05 23:43 UTC (permalink / raw)
  To: Zsh Users List

On Tue, Dec 05, 2006 at 10:40:41AM -0500, Jean-Rene David wrote:
> * TjL [2006.12.05 07:15]:
> > [...]
> > I am currently writing "verbatims" for a class
> > that I am taking.
> > [...]
> > Here is "normal" dialog:
> > 
> > John: How are you today?
> > Tim: I'm good.
> > George: I'm Ok, how are you
> > John: I'm good too.
> > George: Glad to hear it
> > John: Thanks
> > Tim: Yeah, me too
> > 
> > Here is verbatim style dialog:
> > 
> > John1: How are you today?
> > Tim1: I'm good.
> > George1: I'm Ok, how are you
> > John2: I'm good too.
> > George2: Glad to hear it
> > John3: Thanks
> > Tim2: Yeah, me too
> > 
> > [...] You would need separate counters for each
> > person, and you wouldn't know how many people
> > would be a part of the conversation (no fewer
> > than 2 people, probably no more than 10, usually
> > 2-5).
> 
> The 'separate counters for each person' sounds
> like a hash to me, and was suggested by others.
> 
> However I think a text processing tool would be
> more appropriate than a shell for this kind of
> task:

I was thinking the same thing.

> % perl -ne 'BEGIN { %person=(); } \
>           /^([a-zA-Z]+)(:)(.*)$/ &&  \
>             print "$1" . ++$person{$1} . "$2$3\n";' < dialog.file

perl -pe 's/\w+/$& . ++$person{$&}/e' dialog.file

or maybe you don't really want people to understand what you are doing:

perl -pe 's((?=:))?++${$`}?e' dialog.file

Interesting conversation, by the way.

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Scripting situation I cannot wrap my head around
  2006-12-05 23:43   ` Paul Johnson
@ 2006-12-06 19:34     ` TjL
  0 siblings, 0 replies; 6+ messages in thread
From: TjL @ 2006-12-06 19:34 UTC (permalink / raw)
  To: Paul Johnson; +Cc: Zsh Users List

On 12/5/06, Paul Johnson <paul@pjcj.net> wrote:
> On Tue, Dec 05, 2006 at 10:40:41AM -0500, Jean-Rene David wrote:

> > However I think a text processing tool would be
> > more appropriate than a shell for this kind of
> > task:
>
> I was thinking the same thing.

Well all you have is a shell scripting hammer :-)

I had originally thought about using 'read' statements and entering
the conversation directly into the shell, but the more I thought about
it the more it seems like a flat file was the way to go.

Unfortunately the only thing I know about perl is that I've failed to
learn how to use it whenever I tried to learn.


> > % perl -ne 'BEGIN { %person=(); } \
> >           /^([a-zA-Z]+)(:)(.*)$/ &&  \
> >             print "$1" . ++$person{$1} . "$2$3\n";' < dialog.file
>
> perl -pe 's/\w+/$& . ++$person{$&}/e' dialog.file
>
> or maybe you don't really want people to understand what you are doing:
>
> perl -pe 's((?=:))?++${$`}?e' dialog.file

Well I don't really understand either of them, but it works, so I'm
very glad for the help and since it isn't really a zsh question any
more I'll move on.


> Interesting conversation, by the way.

OT - Well the actual verbatims usually are fairly interesting.  I'm
taking a unit of CPE (Clinical Pastoral Education) at a local
hospital.  It involves a lot of knocking on the door and walking into
a room having no idea who you are going to meet and whether or not
they will be welcoming (which happens quite often), hostile (which
happens occasionally), busy/asleep (which happens frequently), or
apathetic to your existence on the planet and presence in their room
(which happes the rest of the time).

Unfortunately the details are covered under HIPPA or HIIPA or however
it's spelled.

Thanks for the help ZshFolk!

TjL


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-12-06 19:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-05  7:31 Scripting situation I cannot wrap my head around TjL
     [not found] ` <237967ef0612050017y1816e7fs66a3bdac8337fac3@mail.gmail.com>
2006-12-05  8:18   ` Mikael Magnusson
2006-12-05 14:35     ` Torur Andreassen
2006-12-05 15:40 ` Jean-Rene David
2006-12-05 23:43   ` Paul Johnson
2006-12-06 19:34     ` TjL

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).