HOw do I write this regular expression
Fruit Price
Banana 0.89 Peach 0.79 Kiwi 1.50 print only the ones ending with vowel using grep and regular expressions. I would be able to figure it out from notes if the lecturer bothered to write them properly. GRRR |
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Code:
grep ".*[aeiou] " fruit.txt Cheers, Tink |
Why do I need the .* in front . I had exactly the same thing except mine didn't have the .*
|
You don't, really. I just like to make clear that I'll be
getting a word, not a single letter. With your sample the results are the same. Cheers, Tink |
I forgot to ask why does the space make a difference? Without the space at the end it prints peach.
|
Because the space determines whether the vowel is
in the middle or at the end of a word. Only "[aeiou]" will match ANY LINE with a vowel in it. ".*[aeiou]" will match anything (including nothing!!) followed by a vowel. ".*[aeiou] " will match the above FOLLOWED by a space (which happens to determine the end of a word). Cheers, Tink |
ah cool.
Next question is on our best friend sed yay!! (being sarcastic) I basically have a script which uses grap to trim out the line on apple so I get apple 1.20. I am REQUIRED to use sed to show just the price. Please explain your answer tinkster sed isn;t particularly easy to use. I think I will appriciate we have PERL!!!! |
Errrh... I won't be doing your homework mate.
Which problem are you facing, what does your sed attempt look like? Cheers, Tink |
Done that question now.
backup:x:34:34:backup:/var/backups:/bin/sh list:x:38:38:Mailing List Manager:/var/list:/bin/sh irc:x:39:39:ircd:/var/run/ircd:/bin/sh gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh nobody:x:65534:65534:nobody:/nonexistent:/bin/sh Debian-exim:x:102:102::/var/spool/exim4:/bin/false identd:x:100:65534::/var/run/identd:/bin/false how come this still displays uid 100 and over and now would i tell grep to work on the uid and not gid? grep '.*[0-99]' /etc/passwd DO i have to filter out the colon and replace it with space? Just guessing thought it may not recognise it as a number with colon in front |
Quote:
fact the regex matches ANYTHING that has at least one digit. Quote:
Cheers, Tink |
I swear this aint in my notes. How do I put two expressions together so either of tham matches print out the lines that match. The | doesn't work
|
I'm sure you'd learn it a lot better if you figured it out yourself. I've just been reading through a book called the 'Linux Cookbook', which covers things like that. Regexp's, it is fairly complicated by the looks of it. I don't know if you've seen that book but it's really good for basics on a whole host of topics.
PS I've even written a review of it if you're interested. Book reviews on this site. |
Quote:
Code:
grep 'x:[0-9][0-9]:' /etc/passwd |
guess what i done it before u posted eddiebaby1023. Wahoooo Am good
|
All times are GMT -5. The time now is 07:07 PM. |