Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
so my "thinking algorithm" is to start with the knife.dat file, read the first row first column value (in this example 5). then use that value of 5 as a "look-up key" in the first column of the snake.dat file, and then use the look-up key (in this example 5) as a knife to cut the head off the snake.dat file and output just the head of the snake, the file head.dat
hi guys,
i need a little awk data manipulation help... i have two files as input files (snake.dat and knife.dat)and i need an awk script to output the head.dat file
so my "thinking algorithm" is to start with the knife.dat file, read the first row first column value (in this example 5). then use that value of 5 as a "look-up key" in the first column of the snake.dat file, and then use the look-up key (in this example 5) as a knife to cut the head off the snake.dat file and output just the head of the snake, the file head.dat
That's certainly one way to do it. Since you need help with your script, why don't you post what you've written/tried so far, and tell us where you're stuck. We're not going to write your scripts for you, though, but will be happy to assist.
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Original Poster
Rep:
oh sorry guys, i had to run off i didn't mean for you all to write it
here's what i've been stabbing at...
BUT!!! in what i've written below, i did one major thing wrong. the knifevalue var should be "looked-up" as the first value in the first column of knife.dat, not user specified (set to 5) as i did below (please don't laugh i don't know how to do that, look up and pass over in a var field.
ok so here's my thinking and 1st attempt to write something
tell awk to look in the 1st column of the first file (snake.dat) for the knifevalue that i told it, on the same line as knifevalue is found in the "nextfile" the second file (knife.dat), when it occurs (it's equal) then print that entire line (there's actually more columns of data than I showed in the example files) to the head.dat file
If i may, is it just a coincidence of data presented that the numbers in the first column are from both files? ie do you want all that match from knife and found in snake to be shown
or only the first number that matches? Also, what happens, assuming current example, if '5' is not in snake but '6' is?
Neither of the current solutions allow for this second scenario.
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Original Poster
Rep:
good morning grail, and the other guys.
yea i just made up the example data, the real data is on a closed lan, i'd love to post it but i can't last night i played with the example data some more at home (not when i do my best thinking) and ran into the same kinds of problems.
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Original Poster
Rep:
actually, the more i play around with the example data and metaschima's command, the more i think it works, maybe your knowledge sees something i don't???
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63
Original Poster
Rep:
thanks metaschima! it makes sense except i'm doomed to messing up FNR and NR
grail, i somewhat had something similar to yours, where you had the variable "x" i had "knifevalue" i just didn't know how to pass in something other than a user defined value. how does your do that? it starts in knife and graps the first rows first column value, then switches to the 2nd file and looks for the greater than or equal to value
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.