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.
don't know if this is the right area for this question, please pardon me if I'm misdirected.....
I'm writing a script that when i pass the parameter to it, it looks in a predetermined file and looks for a string. so far it works sortof. but if input part of a string it finds it but it should find it if i enter the whole string (for example, if i enter "pcd" it finds "pcdebb"). How can I limit it to find the whole string?
I also want to sort results if I have more than one result. would it be better if I redirect the results to a file then sort the file and then display the results?
The line of code I'm using:
grep -i "$1" [filename] || echo "no records found"
well I'll be taking a shell scripting class starting in January, and I have a book on it's way to me that I bought on amazon.com. it's really very interesting as I'm getting more into *nix
since we on the topic of grep, can i ask so more questions on this?
I have a prob wif this prob, i ned to show words that begin wif a single 'z', and that is not adjacent to a vowel and this includes words starting and ending with 'z'.
i am able to get the words that do not have a vowel that is adjacent to 'z' but i cant get those words with a single 'z'. how do i do tat?
i tried grep 'z\{1\}' /usr/share/dict/words but i get no output. when i change to
grep 'z\{2\}' /usr/share/dict/words, i get those words with 2 'z' inside. is this the way to do it or is there another way?
if i get to do a single z, i would ned to find those words that do not have a vowel that is adjacent to 'z' which i did
grep '[^aeiouzAEIOUZ]z' /usr/share/dict/words | grep 'z[^aeiouzAEIOUZ]'
i am able to get the below ouput
yeah I looked around and I can't find the bugger. I shouldn't have given a spoiler on a homework question anyway.
You want to grep for \(either the beginning of a line OR a non-vowel, non-z\) z \(either the end of a line or a non-vowel, non-z\)
So if you look that stuff up in a page that describes regular expressions, you'll have it. I make the assumption that there is one line per word, as is the case in /usr/share/dict/words: otherwise you'll have to look for some other sort of word boundary instead.
Well I've gone this far, so I might as well say that ^ matches the beginning of a line, $ matches the end, and \| gives an "or" effect. I'd be an easy A as a teacher.
1) I cant get words that only contains a single 'z'. in which i tried the method mention in my previous post, and i could not get it. Is there any other way to achieve that aim?
2) /usr/share/dict/words is the path where I am supposed to look into to find the words
3) by doing this
grep '^z\|z$' /usr/share/dict/words
I am able to get words that start wif 'z' or end wif 'z'
but when i tried this
What I said is that i can get words beginning or ending wif 'z', can get words that do not have a vowel that is adjacent to 'z' , but i cant get words that start with a single 'z' or combine all of them together.
i even tried this
egrep '^z|z$|[^aeiouzAEIOUZ]z|z[^aeiouzAEIOUZ]' /usr/share/dict/words
which gives me words such as
waltzes
waltzing
whiz
zonal
zonally
zone
zoned
zones
zoning
zoo
zoological
zoologically
zoom
zooms
zoos
which does not fulfill the conditions at all.
so far do you understand what i am having difficulties with?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.