listing all words starting with $

listing all words starting with $

am 04.01.2008 22:36:54 von Brian Greaney

Hi, a simple(?) newbie question..

Is there a simple way of producing a list of all the words in a text file
that start with a $. I tried cat file | grep '^\$' but that seems to
just give me all the blank lines.

Re: listing all words starting with $

am 04.01.2008 22:48:38 von Ed Morton

On 1/4/2008 3:36 PM, Brian Greaney wrote:
> Hi, a simple(?) newbie question..
>
> Is there a simple way of producing a list of all the words in a text file
> that start with a $. I tried cat file | grep '^\$' but that seems to
> just give me all the blank lines.

I every "word" on a line of it's own or could there be multiple words on a line?
How do you define a "word" - is there some specific set of characters (e.g.
white space, punctuation, digits, etc.) a "word" can/can't contain?

Ed.

Re: listing all words starting with $

am 04.01.2008 22:56:12 von Adam Funk

On 2008-01-04, Brian Greaney wrote:

> Hi, a simple(?) newbie question..
>
> Is there a simple way of producing a list of all the words in a text file
> that start with a $. I tried cat file | grep '^\$' but that seems to
> just give me all the blank lines.

Do you mean all the _words_ that start with "$" or all the _lines_
that start with "$"?


--
Two of the most famous products of Berkeley are LSD and Unix.
I don't think that this is a coincidence. [anonymous]

Re: listing all words starting with $

am 04.01.2008 23:05:47 von Brian Greaney

On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:

>
>
> On 1/4/2008 3:36 PM, Brian Greaney wrote:
>> Hi, a simple(?) newbie question..
>>
>> Is there a simple way of producing a list of all the words in a text file
>> that start with a $. I tried cat file | grep '^\$' but that seems to
>> just give me all the blank lines.
>
> I every "word" on a line of it's own or could there be multiple words on a line?
> How do you define a "word" - is there some specific set of characters (e.g.
> white space, punctuation, digits, etc.) a "word" can/can't contain?
>
> Ed.
Thanks for the prompt response, there can be several words per line, they
are always alpha characters only. Simple example:

write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
AtmIf/$RATMIF Vpt/$RVPI \""

Re: listing all words starting with $

am 04.01.2008 23:19:19 von Cyrus Kriticos

Brian Greaney wrote:
> On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:
>
>>
>> On 1/4/2008 3:36 PM, Brian Greaney wrote:
>>> Hi, a simple(?) newbie question..
>>>
>>> Is there a simple way of producing a list of all the words in a text file
>>> that start with a $. I tried cat file | grep '^\$' but that seems to
>>> just give me all the blank lines.
>> I every "word" on a line of it's own or could there be multiple words on a line?
>> How do you define a "word" - is there some specific set of characters (e.g.
>> white space, punctuation, digits, etc.) a "word" can/can't contain?
>>
>> Ed.
> Thanks for the prompt response, there can be several words per line, they
> are always alpha characters only. Simple example:
>
> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
> AtmIf/$RATMIF Vpt/$RVPI \""

With space as separator:

$ tr ' ' '\n' < filename | grep '^\$'
$Rnode


With space, / and " as separator:

$ tr ' /"' '\n' < filename | grep '^\$'
$ATMIF
$VPI
$PVC
$Rnode
$RATMIF
$RVPI

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.

Re: listing all words starting with $

am 04.01.2008 23:28:46 von Brian Greaney

On Fri, 04 Jan 2008 23:19:19 +0100, Cyrus Kriticos wrote:

> Brian Greaney wrote:
>> On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:
>>
>>>
>>> On 1/4/2008 3:36 PM, Brian Greaney wrote:
>>>> Hi, a simple(?) newbie question..
>>>>
>>>> Is there a simple way of producing a list of all the words in a text file
>>>> that start with a $. I tried cat file | grep '^\$' but that seems to
>>>> just give me all the blank lines.
>>> I every "word" on a line of it's own or could there be multiple words on a line?
>>> How do you define a "word" - is there some specific set of characters (e.g.
>>> white space, punctuation, digits, etc.) a "word" can/can't contain?
>>>
>>> Ed.
>> Thanks for the prompt response, there can be several words per line, they
>> are always alpha characters only. Simple example:
>>
>> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
>> AtmIf/$RATMIF Vpt/$RVPI \""
>
> With space as separator:
>
> $ tr ' ' '\n' < filename | grep '^\$'
> $Rnode
>
>
> With space, / and " as separator:
>
> $ tr ' /"' '\n' < filename | grep '^\$'
> $ATMIF
> $VPI
> $PVC
> $Rnode
> $RATMIF
> $RVPI

Excellent, I think I need to read the man page for tr!
Thank you very much

Re: listing all words starting with $

am 04.01.2008 23:29:49 von Brian Greaney

On Fri, 04 Jan 2008 21:56:12 +0000, Adam Funk wrote:

> On 2008-01-04, Brian Greaney wrote:
>
>> Hi, a simple(?) newbie question..
>>
>> Is there a simple way of producing a list of all the words in a text file
>> that start with a $. I tried cat file | grep '^\$' but that seems to
>> just give me all the blank lines.
>
> Do you mean all the _words_ that start with "$" or all the _lines_
> that start with "$"?

Thanks for your response, as per another post I have a solution. BTW it
was just the words not the lines

Re: listing all words starting with $

am 04.01.2008 23:30:31 von Ed Morton

On 1/4/2008 4:05 PM, Brian Greaney wrote:
> On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:
>
>
>>
>>On 1/4/2008 3:36 PM, Brian Greaney wrote:
>>
>>>Hi, a simple(?) newbie question..
>>>
>>>Is there a simple way of producing a list of all the words in a text file
>>>that start with a $. I tried cat file | grep '^\$' but that seems to
>>>just give me all the blank lines.
>>
>>I every "word" on a line of it's own or could there be multiple words on a line?
>>How do you define a "word" - is there some specific set of characters (e.g.
>>white space, punctuation, digits, etc.) a "word" can/can't contain?
>>
>> Ed.
>
> Thanks for the prompt response, there can be several words per line, they
> are always alpha characters only. Simple example:
>
> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
> AtmIf/$RATMIF Vpt/$RVPI \""
>
>

With GNU awk (to use an RE as the RS):

$ cat file
write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
AtmIf/$RATMIF Vpt/$RVPI \""
$ gawk -v RS='[^[:alpha:]$]' '/^\$/' file
$ATMIF
$VPI
$PVC
$Rnode
$RATMIF
$RVPI

Regards,

Ed.

Re: listing all words starting with $

am 04.01.2008 23:34:14 von Loki Harfagr

On Fri, 04 Jan 2008 22:05:47 +0000, Brian Greaney wrote:

> On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:
>
>
>>
>> On 1/4/2008 3:36 PM, Brian Greaney wrote:
>>> Hi, a simple(?) newbie question..
>>>
>>> Is there a simple way of producing a list of all the words in a text
>>> file that start with a $. I tried cat file | grep '^\$' but that seems
>>> to just give me all the blank lines.
>>
>> I every "word" on a line of it's own or could there be multiple words
>> on a line? How do you define a "word" - is there some specific set of
>> characters (e.g. white space, punctuation, digits, etc.) a "word"
>> can/can't contain?
>>
>> Ed.
> Thanks for the prompt response, there can be several words per line,
> they are always alpha characters only. Simple example:
>
> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to
> $Rnode AtmIf/$RATMIF Vpt/$RVPI \""

If the special sep starter ($) can't be the first
char ever you should be OK with a simple:

# awk 'NR>1{print $1}' RS=$ yourfile

like, with your sample:

$ echo 'set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
> AtmIf/$RATMIF Vpt/$RVPI \"' | awk 'NR>1{print $1}' RS=$
ATMIF
VPI
PVC
Rnode
RATMIF
RVPI

Re: listing all words starting with $

am 04.01.2008 23:47:43 von Brian Greaney

On Fri, 04 Jan 2008 16:30:31 -0600, Ed Morton wrote:

>
>
> On 1/4/2008 4:05 PM, Brian Greaney wrote:
>> On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:
>>
>>
>>>
>>>On 1/4/2008 3:36 PM, Brian Greaney wrote:
>>>
>>>>Hi, a simple(?) newbie question..
>>>>
>>>>Is there a simple way of producing a list of all the words in a text file
>>>>that start with a $. I tried cat file | grep '^\$' but that seems to
>>>>just give me all the blank lines.
>>>
>>>I every "word" on a line of it's own or could there be multiple words on a line?
>>>How do you define a "word" - is there some specific set of characters (e.g.
>>>white space, punctuation, digits, etc.) a "word" can/can't contain?
>>>
>>> Ed.
>>
>> Thanks for the prompt response, there can be several words per line, they
>> are always alpha characters only. Simple example:
>>
>> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
>> AtmIf/$RATMIF Vpt/$RVPI \""
>>
>>
>
> With GNU awk (to use an RE as the RS):
>
> $ cat file
> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to $Rnode
> AtmIf/$RATMIF Vpt/$RVPI \""
> $ gawk -v RS='[^[:alpha:]$]' '/^\$/' file
> $ATMIF
> $VPI
> $PVC
> $Rnode
> $RATMIF
> $RVPI
>
> Regards,
>
> Ed.
Hey! an even better solution, the tr option gave me some 'hits' I didn't
want, but could live with (numbers & trailing characters). This awk
solution is right on.
What a brilliant newsgroup this is, thanks again!

Re: listing all words starting with $

am 05.01.2008 01:55:12 von someone

Brian Greaney wrote:
> Hi, a simple(?) newbie question..
>
> Is there a simple way of producing a list of all the words in a text file
> that start with a $. I tried cat file | grep '^\$' but that seems to
> just give me all the blank lines.

perl -lne'print for /\$\w+/g'


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: listing all words starting with $

am 05.01.2008 09:34:35 von Loki Harfagr

On Fri, 04 Jan 2008 22:47:43 +0000, Brian Greaney wrote:

> On Fri, 04 Jan 2008 16:30:31 -0600, Ed Morton wrote:
>
>
>>
>> On 1/4/2008 4:05 PM, Brian Greaney wrote:
>>> On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:
>>>
>>>
>>>
>>>>On 1/4/2008 3:36 PM, Brian Greaney wrote:
>>>>
>>>>>Hi, a simple(?) newbie question..
>>>>>
>>>>>Is there a simple way of producing a list of all the words in a text
>>>>>file that start with a $. I tried cat file | grep '^\$' but that
>>>>>seems to just give me all the blank lines.
>>>>
>>>>I every "word" on a line of it's own or could there be multiple words
>>>>on a line? How do you define a "word" - is there some specific set of
>>>>characters (e.g. white space, punctuation, digits, etc.) a "word"
>>>>can/can't contain?
>>>>
>>>> Ed.
>>>
>>> Thanks for the prompt response, there can be several words per line,
>>> they are always alpha characters only. Simple example:
>>>
>>> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to
>>> $Rnode AtmIf/$RATMIF Vpt/$RVPI \""
>>>
>>>
>>>
>> With GNU awk (to use an RE as the RS):
>>
>> $ cat file
>> write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to
>> $Rnode AtmIf/$RATMIF Vpt/$RVPI \""
>> $ gawk -v RS='[^[:alpha:]$]' '/^\$/' file
>> $ATMIF
>> $VPI
>> $PVC
>> $Rnode
>> $RATMIF
>> $RVPI
>>
>> Regards,
>>
>> Ed.
> Hey! an even better solution, the tr option gave me some 'hits' I didn't
> want, but could live with (numbers & trailing characters). This awk
> solution is right on.

Ed, though I prefer your expression as it uses
the implicit 'print' method wouldn't those simple
ones work as well?

$ awk 'NR>1{print "$"$1}' RS=$ file
$ awk 'NR>1{print OFS $1}' RS=$ OFS="$" file

What special cases do you protect from with your extended RS ?
(I suppose I'll find out in one ohnosecond :-)

Re: listing all words starting with $

am 06.01.2008 00:54:16 von Ed Morton

On 1/5/2008 2:34 AM, loki harfagr wrote:
> On Fri, 04 Jan 2008 22:47:43 +0000, Brian Greaney wrote:
>
>
>>On Fri, 04 Jan 2008 16:30:31 -0600, Ed Morton wrote:
>>
>>
>>
>>>On 1/4/2008 4:05 PM, Brian Greaney wrote:
>>>
>>>>On Fri, 04 Jan 2008 15:48:38 -0600, Ed Morton wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>On 1/4/2008 3:36 PM, Brian Greaney wrote:
>>>>>
>>>>>
>>>>>>Hi, a simple(?) newbie question..
>>>>>>
>>>>>>Is there a simple way of producing a list of all the words in a text
>>>>>>file that start with a $. I tried cat file | grep '^\$' but that
>>>>>>seems to just give me all the blank lines.
>>>>>
>>>>>I every "word" on a line of it's own or could there be multiple words
>>>>>on a line? How do you define a "word" - is there some specific set of
>>>>>characters (e.g. white space, punctuation, digits, etc.) a "word"
>>>>>can/can't contain?
>>>>>
>>>>> Ed.
>>>>
>>>>Thanks for the prompt response, there can be several words per line,
>>>>they are always alpha characters only. Simple example:
>>>>
>>>>write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to
>>>>$Rnode AtmIf/$RATMIF Vpt/$RVPI \""
>>>>
>>>>
>>>>
>>>
>>>With GNU awk (to use an RE as the RS):
>>>
>>>$ cat file
>>>write2file "set atmif/$ATMIF vpt/$VPI vpd correlationTag \"$PVC to
>>>$Rnode AtmIf/$RATMIF Vpt/$RVPI \""
>>>$ gawk -v RS='[^[:alpha:]$]' '/^\$/' file
>>>$ATMIF
>>>$VPI
>>>$PVC
>>>$Rnode
>>>$RATMIF
>>>$RVPI
>>>
>>>Regards,
>>>
>>> Ed.
>>
>>Hey! an even better solution, the tr option gave me some 'hits' I didn't
>>want, but could live with (numbers & trailing characters). This awk
>>solution is right on.
>
>
> Ed, though I prefer your expression as it uses
> the implicit 'print' method wouldn't those simple
> ones work as well?
>
> $ awk 'NR>1{print "$"$1}' RS=$ file
> $ awk 'NR>1{print OFS $1}' RS=$ OFS="$" file
>
> What special cases do you protect from with your extended RS ?
> (I suppose I'll find out in one ohnosecond :-)

They'd fail if words weren't always white-space separated, e.g. the output below
should be "$def":

$ echo "abc \$def,ghi"
abc $def,ghi
$ echo "abc \$def,ghi" | awk -v RS='[^[:alpha:]$]' '/^\$/'
$def
$ echo "abc \$def,ghi" | awk 'NR>1{print "$"$1}' RS=$
$def,ghi

The OP just said that the words were all alphabetic, he didn't say they had to
be terminated by white space.

Ed.