AWK: How to display how array elements are found in data file?
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.
AWK: How to display how array elements are found in data file?
Hello and thanks for reading my post, I really appreciate it.
Need a way to read from the arrayfile and search the datafile in a way that prints out how the arrayfile elements are found. An awk one liner is preferred.
arrayfile:
Code:
haha
hahh
datafile:
Code:
aaahahahaaaahahahhaaahahahaaahahaaaa
desiredoutputfile:
Code:
haha 1110111
hahh 0001000
So its basically remove the last character from the arrayfile elements, search the datafile until you find the match, and if the next character after match is the same as was removed then write a 1 and if not then write a 0, It also needs to search in the most squeezed way possible (from beginning of each character in datafile, not by blocks like normal search in text editor, as portrayed in my previous post: https://www.linuxquestions.org/quest...98#post5847798).
Thank you infinitely.
Last edited by starrysky1; 05-02-2018 at 01:57 PM.
Hello and thanks for reading my post, I really appreciate it. Need a way to read from the arrayfile and search the datafile in a way that prints out how the arrayfile elements are found. An awk one liner is preferred.
arrayfile:
Code:
haha
hahh
datafile:
Code:
aaahahahaaaahahahhaaahahahaaahahaaaa
desiredoutputfile:
Code:
haha 1110111
hahh 0001000
So its basically remove the last character from the arrayfile elements, search the datafile until you find the match, and if the next character after match is the same as was removed then write a 1 and if not then write a 0, It also needs to search in the most squeezed way possible (from beginning of each character in datafile, not by blocks like normal search in text editor, as portrayed in my previous post: https://www.linuxquestions.org/quest...98#post5847798).
Read the "Question Guidelines" link in my posting signature. We're happy to help, but just telling us what you want and not showing your own efforts to solve your own problem, isn't a good thing. This is something you've done in many previous threads as well.
Not only do I agree 100% with TB0ne, but how is this any different than the linked previous question? What attempts to alter the suggested previous solution have you made to allow for whatever seems
to be your new criteria?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.