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.
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
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).
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!!!!
Originally posted by linuxmandrake
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
grep '.*[0-99]' /etc/passwd
Because the period matches a 1 and the 0 matches a zero, in
fact the regex matches ANYTHING that has at least one digit.
Quote:
and over and now would i tell grep to work on the uid and not gid?
By exploiting the fact that the uid is preced by "x:" and the gid isn't.
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.
Originally posted by linuxmandrake 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
The square brackets match exactly one character, not a range of integer values. [0-9] will match a single character in the range 0 thru 9, so your pattern is matching zero or more of any character (the ".*") followed by a single character in the range 0 thru 9 or 9 (so the second 9 is redundant). Simple pattern to match your sample text:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.