Timeline for Matching 2 main columns between files; and paste other columns into the output file when those main columns match. Keep row size of 1st file intact
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 23, 2017 at 11:33 | history | edited | CommunityBot | replaced http://stackoverflow.com/ with https://stackoverflow.com/ | |
| Jan 6, 2016 at 17:37 | vote | accept | Noobie123 | ||
| Dec 17, 2015 at 19:54 | history | edited | G-Man Says 'Reinstate Monica' | CC BY-SA 3.0 | Responded to comments. |
| Dec 17, 2015 at 17:22 | vote | accept | Noobie123 | ||
| Jan 6, 2016 at 17:37 | |||||
| Dec 17, 2015 at 17:20 | comment | added | Noobie123 | Lastly, { # file1 key = $1 "," $3 if (present[key]) print $1, $2, $3, $4, minor8[key] else print $1, $2, $3, $4, "-" } I can see you are "printing" each column separately. What if my file has 100s of columns. Isn't there a shorter way to do this? I tried $1-4 (for instance), or $1-$4, but that didn't work. | |
| Dec 17, 2015 at 17:19 | comment | added | Noobie123 | NR==FNR { # file3 key = $1 "," $2 present[key] = 1 minor9[key] = $3 next } and "present[key] = 1" <-- what exactly are you telling Linux here. Are you putting an array equal to 1? And why "1"? And is "present" a randomly chosen name for the array, or is it a standard way for Linux to represent the current/present file... | |
| Dec 17, 2015 at 17:15 | comment | added | Noobie123 | Hi G-Man. Thanks a lot. This works wonderfully. Exactly what I needed. Since I'm still learning, I was wondering if you could explain me (the noobie that I am) the following lines of your code BEGIN {IFS = "\t" OFS = "\t"} Although I indeed specified that my files are tab separated, what does it mean to specify both IFS and OFS? NR==FNR { # file2 key = $2 "," $3 present[key] = 1 minor8[key] = $1 next } Why is it necessary to put a "," between two columns? Does that tell Linux to use both columns, or something of the sort? | |
| Dec 16, 2015 at 21:31 | history | answered | G-Man Says 'Reinstate Monica' | CC BY-SA 3.0 |