|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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] |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 \"" |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|