PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > listing all words starting with $
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

listing all words starting with $

Réponse
 
LinkBack Outils de la discussion
Vieux 04/01/2008, 21h36   #1
Brian Greaney
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut listing all words starting with $

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.
  Réponse avec citation
Vieux 04/01/2008, 21h48   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing all words starting with $



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.

  Réponse avec citation
Vieux 04/01/2008, 21h56   #3
Adam Funk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing all words starting with $

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]
  Réponse avec citation
Vieux 04/01/2008, 22h05   #4
Brian Greaney
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing all words starting with $

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 \""


  Réponse avec citation
Vieux 04/01/2008, 22h19   #5
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing all words starting with $

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.
  Réponse avec citation
Vieux 04/01/2008, 22h28   #6
Brian Greaney
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing all words starting with $

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

  Réponse avec citation
Vieux 04/01/2008, 22h29   #7
Brian Greaney
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing all words starting with $

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

  Réponse avec citation
Vieux 04/01/2008, 22h30   #8
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing all words starting with $



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.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h42.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13787 seconds with 16 queries