public inbox for speakup@linux-speakup.org
 help / color / mirror / Atom feed
* bash regular expressions
@  Ned
   ` Lorenzo Taylor
   ` Ralph W. Reid
  0 siblings, 2 replies; 5+ messages in thread
From: Ned @  UTC (permalink / raw)
  To: Speakup is a screen review system for Linux.

Hi all,

I wrote a bash script and all but the two commands below were marked wrong, so I need to correct them. Hope you don't mind pointing out my mistakes:
1. needs to output how many lines are there with a . (period) in them. I used the escape char \ before the period, but it apparently didn't work.

echo Output the number of lines that have a \"\.\" \(period\):
grep -c \. ./test.file

2. this one needs to output the number of lines containing the string '/*':

echo Output the number of lines that have the string \"'/'\*\":
grep -c /\* ./test.file


Thanks a lot in advance!
Ned

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

* Re: bash regular expressions
   bash regular expressions Ned
@  ` Lorenzo Taylor
     ` Ned
     ` Sean McMahon
   ` Ralph W. Reid
  1 sibling, 2 replies; 5+ messages in thread
From: Lorenzo Taylor @  UTC (permalink / raw)
  To: Speakup is a screen review system for Linux.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ned's comments on bash regular expressions were as follows:
# I wrote a bash script and all but the two commands below were marked wrong, so I need to correct them. Hope you don't mind pointing out my mistakes:

Well, I'll see what I can do.  Here goes nothing! <smile>

# 1. needs to output how many lines are there with a . (period) in them. I used the escape char \ before the period, but it apparently didn't work.
# 
# echo Output the number of lines that have a \"\.\" \(period\):
# grep -c \. ./test.file

Try:

echo Output the number of lines that have a \".\" \(period\):
grep -c [.] ./test.file

I can't explain it, but somehow it only works that way.  Escaping the period
doesn't help.  It must be specified in a range by itself.

# 2. this one needs to output the number of lines containing the string '/*':
# 
# echo Output the number of lines that have the string \"'/'\*\":
# grep -c /\* ./test.file

Try this instead:

echo Output the number of lines that have the string '"/*"':
grep -c [/][*] ./test.file

Again, each character seems as though it must be enclosed in range brackets by
itself.  Not exactly sure why without further digging in manpages for grep(1) and
regex(3), which is something I may do in the future if the mood hits me, but as
long as this works, I just don't feel like it right now. <smile>

HTH,
Lorenzo
- -- 
"We decided that we should evaluate the Microsoft offerings first. Once we
realised what a powerful set of tools they were, it became self-evident this was
the right way to go down."

Microsoft: the right way to go down
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCUcevG9IpekrhBfIRAs1uAJ9/qfMLcyIuzP19Tx8I5HlIbEC/VACeJHod
RaMPPXLUHrKsBmDFYk2f2p4=
=R6qv
-----END PGP SIGNATURE-----


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

* Re: bash regular expressions
   ` Lorenzo Taylor
@    ` Ned
     ` Sean McMahon
  1 sibling, 0 replies; 5+ messages in thread
From: Ned @  UTC (permalink / raw)
  To: Speakup is a screen review system for Linux.

Thanks bro,
it definitely works.
Now, as you pointed out, why the \ is not enough, we'll leave that for some 
later time.

Ned
----- Original Message ----- 
From: "Lorenzo Taylor" <lorenzo@taylor.homelinux.net>
To: "Speakup is a screen review system for Linux." <speakup@braille.uwo.ca>
Sent: Monday, April 04, 2005 4:03 PM
Subject: Re: bash regular expressions


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ned's comments on bash regular expressions were as follows:
> # I wrote a bash script and all but the two commands below were marked 
> wrong, so I need to correct them. Hope you don't mind pointing out my 
> mistakes:
>
> Well, I'll see what I can do.  Here goes nothing! <smile>
>
> # 1. needs to output how many lines are there with a . (period) in them. I 
> used the escape char \ before the period, but it apparently didn't work.
> #
> # echo Output the number of lines that have a \"\.\" \(period\):
> # grep -c \. ./test.file
>
> Try:
>
> echo Output the number of lines that have a \".\" \(period\):
> grep -c [.] ./test.file
>
> I can't explain it, but somehow it only works that way.  Escaping the 
> period
> doesn't help.  It must be specified in a range by itself.
>
> # 2. this one needs to output the number of lines containing the string 
> '/*':
> #
> # echo Output the number of lines that have the string \"'/'\*\":
> # grep -c /\* ./test.file
>
> Try this instead:
>
> echo Output the number of lines that have the string '"/*"':
> grep -c [/][*] ./test.file
>
> Again, each character seems as though it must be enclosed in range 
> brackets by
> itself.  Not exactly sure why without further digging in manpages for 
> grep(1) and
> regex(3), which is something I may do in the future if the mood hits me, 
> but as
> long as this works, I just don't feel like it right now. <smile>
>
> HTH,
> Lorenzo
> - -- 
> "We decided that we should evaluate the Microsoft offerings first. Once we
> realised what a powerful set of tools they were, it became self-evident 
> this was
> the right way to go down."
>
> Microsoft: the right way to go down
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.0 (GNU/Linux)
>
> iD8DBQFCUcevG9IpekrhBfIRAs1uAJ9/qfMLcyIuzP19Tx8I5HlIbEC/VACeJHod
> RaMPPXLUHrKsBmDFYk2f2p4=
> =R6qv
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Speakup mailing list
> Speakup@braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup 



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

* Re: bash regular expressions
   ` Lorenzo Taylor
     ` Ned
@    ` Sean McMahon
  1 sibling, 0 replies; 5+ messages in thread
From: Sean McMahon @  UTC (permalink / raw)
  To: Speakup is a screen review system for Linux.

I also find it's best to execute the commands by themselves before including
them in some massive script.  Helps the diagnosis.
----- Original Message ----- 
From: "Lorenzo Taylor" <lorenzo@taylor.homelinux.net>
To: "Speakup is a screen review system for Linux." <speakup@braille.uwo.ca>
Sent: Monday, April 04, 2005 4:03 PM
Subject: Re: bash regular expressions


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ned's comments on bash regular expressions were as follows:
> # I wrote a bash script and all but the two commands below were marked wrong,
so I need to correct them. Hope you don't mind pointing out my mistakes:
>
> Well, I'll see what I can do.  Here goes nothing! <smile>
>
> # 1. needs to output how many lines are there with a . (period) in them. I
used the escape char \ before the period, but it apparently didn't work.
> #
> # echo Output the number of lines that have a \"\.\" \(period\):
> # grep -c \. ./test.file
>
> Try:
>
> echo Output the number of lines that have a \".\" \(period\):
> grep -c [.] ./test.file
>
> I can't explain it, but somehow it only works that way.  Escaping the period
> doesn't help.  It must be specified in a range by itself.
>
> # 2. this one needs to output the number of lines containing the string '/*':
> #
> # echo Output the number of lines that have the string \"'/'\*\":
> # grep -c /\* ./test.file
>
> Try this instead:
>
> echo Output the number of lines that have the string '"/*"':
> grep -c [/][*] ./test.file
>
> Again, each character seems as though it must be enclosed in range brackets by
> itself.  Not exactly sure why without further digging in manpages for grep(1)
and
> regex(3), which is something I may do in the future if the mood hits me, but
as
> long as this works, I just don't feel like it right now. <smile>
>
> HTH,
> Lorenzo
> - -- 
> "We decided that we should evaluate the Microsoft offerings first. Once we
> realised what a powerful set of tools they were, it became self-evident this
was
> the right way to go down."
>
> Microsoft: the right way to go down
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.0 (GNU/Linux)
>
> iD8DBQFCUcevG9IpekrhBfIRAs1uAJ9/qfMLcyIuzP19Tx8I5HlIbEC/VACeJHod
> RaMPPXLUHrKsBmDFYk2f2p4=
> =R6qv
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Speakup mailing list
> Speakup@braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup



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

* Re: bash regular expressions
   bash regular expressions Ned
   ` Lorenzo Taylor
@  ` Ralph W. Reid
  1 sibling, 0 replies; 5+ messages in thread
From: Ralph W. Reid @  UTC (permalink / raw)
  To: Speakup is a screen review system for Linux.

Your search strings are not in quotes, and are therefore interpreted
by the shell directly instead of by `grep`..  For this particular set
of cases, either single or double quotes will work.  For differences
in the single and double quotes which can make a difference in other
cases, see the man page for the shell you are using (most likely
`bash).  For the man page for `bash, enter the following command at
your system prompt:

man bash

Note that as I said before, the `bash` man page is somewhat lengthy,
but there is a lot of good stuff in there.  Here is an example of one
command which solves one of your problems--I leave the other problem
for you to figure out as an exercise:

grep -c "\." ./testfile.txt

HTH, and keep on learnin' :) .

On Mon, Apr 04, 2005 at 10:22:11AM -0700, Ned wrote:
> Hi all,
> 
> I wrote a bash script and all but the two commands below were marked wrong, so I need to correct them. Hope you don't mind pointing out my mistakes:
> 1. needs to output how many lines are there with a . (period) in them. I used the escape char \ before the period, but it apparently didn't work.
> 
> echo Output the number of lines that have a \"\.\" \(period\):
> grep -c \. ./test.file
> 
> 2. this one needs to output the number of lines containing the string '/*':
> 
> echo Output the number of lines that have the string \"'/'\*\":
> grep -c /\* ./test.file
> 
> 
> Thanks a lot in advance!
> Ned
> _______________________________________________
> Speakup mailing list
> Speakup@braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup

-- 
Ralph.  N6BNO.  Wisdom comes from central processing, not from I/O.
rreid@sunset.net  http://personalweb.sunset.net/~rreid
...passing through The City of Internet at the speed of light!
CIRCLE AREA = _pi * r ^ 2


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

end of thread, other threads:[~ UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
 bash regular expressions Ned
 ` Lorenzo Taylor
   ` Ned
   ` Sean McMahon
 ` Ralph W. Reid

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 read-only IMAP folder(s) and NNTP newsgroup(s).