ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?
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.
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
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
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.
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].*'
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.