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 want to grep the patterns in such a way that i get
either SIA/ZMR (middle terms of the 1st and 2nd column) in the 1st column and either SIA/ZMR again in the 2nd column and the 3rd column will be score as usual......
Actually it's a NACUUOC (Not A Completely Useless Use Of cat) -- cat'ing a file into a short command being iteratively developed on the CLI makes the heart of it, in this case the regex, more accessible for editing. I do it all the time, although I do usually remove the cat later.
I don't understand the "ZMR.*(ZMR|SIA)|SIA" part of the regex. Wouldn't:
A final soln should probably not use it unless you need to. Shorter lines are easier to read / debug (unless its really obscure).
I can see this degenerating into style discussion
Actually, it can make a difference sometimes (using '|') eg you can echo a string through the wc cmd and get num of words, but you can't use the wc cmd on a string eg
you can
string="one two three"
echo $line|wc -w
but you can't
wc -w $string
in the latter case wc insists on a filename as the input.
Actually it's a NACUUOC (Not A Completely Useless Use Of cat) -- cat'ing a file into a short command being iteratively developed on the CLI makes the heart of it, in this case the regex, more accessible for editing. I do it all the time, although I do usually remove the cat later.
But there's a better solution for that. Put the filename first using redirection:
Code:
<filename egrep "ZMR.*(ZMR|SIA)|SIA.*(ZMR|SIA)"
Last edited by Telemachos; 10-12-2008 at 06:29 AM.
I wonder if that "word order" doesn't spring to my mind because of having English as a native language. Would a speaker of Latin, used to having word order make almost difference to the meaning of a sentence, be more likely to think of that?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.