I have about 3000 files that I want to search. The first column in all of these 3000 files has a unique serial number on each line. The subsequent columns have lots of data.
I have another masterfile with three columns to help me find all the data I need in a moments notice:
what I want to do take list of serial numbers, get the file name and row number for where the data sits, and then spit out the data into one file. I figured awk getline might help call up the filename and row name to go searching, but I am really confused with this command.
Another thought was to make a shell script to go down each row in the masterfile, create a variable for "row number variable" and one for "filenamevariable" and then awk '(NF=rownumbervariable){print $0}' filenamevariable >>outputfile
thanks for the speedy reply. I understand each individual element in your code, but since I'm not sure what it is "saying", I'm not sure how to set this up for my data....can you elaborate briefly please?
also, is it not helpful to use the file name and row number to help awk figure out where to look?
it most definitely works!
what I understand from the code is that you are creating an array that puts all of the serial numbers together and then testing each line of the array as a pattern in all of the files.
My concern is the length of time this will take over 64GB of data...I havent tried this yet, but will get the LSF farm going to see what happens. Is there a way to use the file name and row number to speed things up?
This will open and close only those files that are specified in subset.txt and look for the right line number and print the record it finds on that line. For efficiency reasons subset.txt would best be sorted..
Incidentally, what intuitively is meant by while (!p && getline x<f)
I understand the second part to mean "as long getline returns an actual line from file 'f' "
but I'm not understanding where the 'p' comes in. I see the downstream code for 'p' but it still isn't sinking in.
Strange. Are you on Solaris? If so use nawk or /usr/xpg4/bin/awk instead of standard awk.
It means while the variable p is empty or zero AND reading a line was successful (in other words no EOF was encountered). If the variable p equals 0 then !p equals 1 (i.e. "TRUE")