LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2004, 11:46 PM   #16
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43

I think that is the question as I understood it. I made the assumption that it should match words like "zffz": if that is not acceptable then you can just pipe the result through "grep -v 'z.*z' ".

All you have to do is translate this:
Code:
\(either the beginning of a line OR a non-vowel, non-z character \) z \(either the end of a line OR a non-vowel, non-z character \)
into a regular expression. The translation is very direct.
 
Old 03-27-2004, 11:56 PM   #17
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
hi

Yes, the words found should only contain a single z so zffz is not acceptable.

\(either the beginning of a line OR a non-vowel, non-z character \) z \(either the end of a line OR a non-vowel, non-z character \)

=>is this it?
\(^[^aeiouzAEIOUZ]\)z\([^aeiouzAEIOUZ]$\)

If this is it then i dun tink i can get hte answer for both grep or egrep.
Sorry to say this bu ti dun quite understand ur pseudocode for the above, I just touch on LInux at the beginning of this month aka newbie woth poor english.

Mayb if you could furthur elaborate? or point out my mistakes?
 
Old 03-28-2004, 12:01 AM   #18
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
That's almost exactly it. You need to use '\|' when you mean OR, and you might want to change the z in the middle to [zZ]. Alternatively, you could leave everything lowercase and use the -i option to grep.

I've written this for grep, not egrep. You probably have to add or remove some backslashes in order to switch between them.
 
Old 03-28-2004, 12:14 AM   #19
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
thanks

hi

ok so with what you said, this shld be it

'\(^\|[^aeiouzAEIOUZ]\)z\([^aeiouzAEIOUZ]\|$\)'

and the full command is

grep -i '\(^\|[^aeiouzAEIOUZ]\)z\([^aeiouzAEIOUZ]\|$\)' /usr/share/dict/words

and yes i tink i got it.

ok u r good.

sorry for the previous tries.

(anyway i din know we can use () inside the expression. I hve nvr come across the use of this ().)

=>ok mayb tis is how i see ur command.

beginning wif z, no vowels infront of z, no vowels after z, ending wif z

is that rite?...just use it like a mathematical quesiotn? multiply z into the brackets and split them up?.m i correct?

Last edited by xfiles_wolvie; 03-28-2004 at 12:34 AM.
 
Old 03-28-2004, 12:39 AM   #20
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
If im correct, can u help me with another prob.

im trying to get lower case words in the same path as above but i cant. this aim is part of another question but i would wan to tackle this part 1st.

i try
grep [:lower:] /usr/share/dict/words
but they still show upper case letters.
patterns that i tried include
[[:lower:]], '[:lower:]', '[[:lower:]]', "[:lower:]", "[[:lower:]]", '[^[:upper:]]', "[^[:upper:]]"

but to no avail. How do i do that? its such a simple command and yet i failed to achieve that. I m clueless. i try egrep oso, bt to no avail.

anyway the whole question requires these conditions

all words containing 'ae', beginning with lowercase letter, not beginning or ending with 'ae', assume 'ae' appears only once in each line and do this in 1 regular expression.

i m able to get not beginning or ending with ae with this
grep '[^ae]\|[ae$]' /usr/share/dict/words

containing wif 'ae'
grep 'ae' /usr/share/dict/words

but not the small caps words. Can you help?
 
Old 03-28-2004, 09:26 AM   #21
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
For the first command, don't forget to pipe the result through something like "grep -vi 'z.*z' " to get rid of words with two nonadjacent z's.

For lowercase words, you're on the right track but you forgot that grep finds *any* occurence of what you search for. So for example grep '[[:lower:]]' would find any word with at least one lowercase letter. You could solve this in one of two ways:
  • Use the -v switch to grep to find words not containing an uppercase letter
  • Search for the beginning of a line followed by some lowercase letters followed by the end of a line
 
Old 03-31-2004, 07:13 AM   #22
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
Hi

thanks for the tip. But in the 1st command w/o using the grep command, there are no words that contain 2 non adjacent z. Thanks.

Oh yes thanks for reminding about the -v option and the using of the [:upper:].

Can I also check with you, if this command works for you?
grep 'z{2}' /usr/share/dict/words

or is this command?
grep z\{2\} /usr/share/dict/words

or this command?
grep 'z\{2\}' /usr/share/dict/words

which command will display words with 2 z in it? I tried all 3, and only the last command works. May I know why isit so?
 
Old 03-31-2004, 10:28 AM   #23
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
the second command (the one without 's) doesn't work because the shell interprets the \s as escaping the {s before ever calling grep, so the second command is equivalent to the first. In the third, the 's keep the shell from interpreting the stuff inside them, so grep gets all of what you typed (excepting the 's of course). The \s turn on grep's special meaning for {.

If you use egrep, the first two will work but the third won't, since { has special meaning by default in egrep, and \ turns it off.
 
Old 04-01-2004, 06:33 AM   #24
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
Hi,

thanks. some how I was told the other way round. No wonder i cant figure out whose the rite 1. Since u clarify it for me, im grateful. thanks.

ok here's another prob that i encounter...mayb u can guide me like wat u did initially,as in tell me in pseudocode or something like tat. thanks

I have a text file, which contains 4 columns of words and numbers separated with a tab

1st col= ID (numeric)
2nd col= Name (alphabets)
3rd col= Hours worked (Numeric)
4th col= Hourly Pay (Numeric)

I would need to get the ID and hours worked for employees whose hourly pay is more than 20.
I tried
cut -f1,3,4 | grep '.*[2-9].*'
cut -f1,3,4 | grep '.*[^0-1].*'

Any advice?
 
Old 04-01-2004, 09:48 AM   #25
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
Are you familiar with awk? If not, see its man page. This becomes *really* easy if you do use awk.
 
Old 04-01-2004, 10:03 AM   #26
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
Hi,

ya i do know abt awk a little. but i was told to skip awk...i hve no idea why...seems so easy with awk. sigh. anyway can i ask you if new hampshire is in UK or US?
 
Old 04-01-2004, 10:25 AM   #27
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
Hi,

do you know about ed editor?.

i tried

a testing
a "testing"
a 'testing'

in order to add a few lines but to no avail. any advice?
 
Old 04-11-2004, 11:51 PM   #28
shepherd
LQ Newbie
 
Registered: Apr 2004
Posts: 1

Rep: Reputation: 0
egrep solution...

try

grep -Ev '(za)|(ze)|(zi)|(zo)|(zu)' FILENAME

?
 
Old 04-12-2004, 10:05 AM   #29
xfiles_wolvie
Member
 
Registered: Mar 2004
Location: Singapore
Distribution: RH 9.0
Posts: 34

Rep: Reputation: 15
tat is another idea of doing it...let me try n get back to u..thanks
 
Old 07-12-2012, 06:53 AM   #30
ashishkumar1000
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Rep: Reputation: Disabled
you can try with this... this should work..

grep "[z]\{1\\}" file.txt | grep -v "z[aeiouAEIOU]" | grep -v "[aeiouAEIOU]z"

where file.txt is the name of your file
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
help on grep!!!! sanjith11 Programming 5 01-20-2005 05:43 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 01:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration