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 am attempting to match lines in a huge log files, reading each line into an array then righting it to an email. That part is easy, now they want me to print only certain lines out. I have a 2nd array thats sole job is to be used to match a field. I can do it in with three individual IF statements.
Is there an easier way to do it, with the =~ like $a[1] =~ %b ???? or something that? To compare the field to the entire 2nd array at once?
You mean a boolean OR of each element of the second array as the match string? Why not just do that (i.e., just collapse your array into a single string separated by ‘|’)?
Actually, the orig qn has varied a bit.
I was orig thinking of an answer to post #3 ie 1 element compared to an array.
However, if OP wants to compare a list/array of elements against the input file/array, then combine your approach ie create an ORed regex and use my grep to match against the whole file/array.
Note that this may not be a good idea if the post 1 ('huge file') is accurate.
You'd be doing against 1 rec at a time if its too big to (easily) fit in mem, although I suppose you could do it in blocks of eg 100 lines at a time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.