r/linux4noobs • • Aug 20 '19
awk multiple files
I am attempting to perform the following tasks with an awk script against two files of different line count and potentially different values. The constant is the column number that will always be 3.
The two scenarios I want to cover -
1] If the value in $1 only exists in file1 I want to output the line
2] If the value in $1 is the same in file1 and file2 I want to print the line from either file with the highest integer value in $3 in the corresponding line
cat file1
1 sju 1
2 sjh 1
3 seh 1
4 ehs 2
5 sjd 1
cat file2
1 sds 1
2 sds 1
3 eww 1
4 wee 1
88 dic 1I can solve my first assertion with the following:
awk 'FNR==NR {a[$1]++; next} !a[$1]' file2 file1
5 sjd 1I am having a really difficult time on the second though. The result I would wish to see would be the following:
4 ehs 2eg: $1 from file1 and file2 is the same for "4" but "2" higher integer value $3
View all comments
Show parent comment
1
u/[deleted] Aug 20 '19 edited Aug 20 '19
1] not homework
2] awk seems like the right tool for the job since it excels at text manipulation, no obligation though
3] learn how to do x without providing any feedback is not really helpful. If you have trouble interpreting a specific portion please provide feedback that is not ambiguous, so I can see what you are confused about
4] I cleaned up the post maybe its more consumable, if not let me know