I’m taking two input files, one with certain ID numbers, and another with a large list of ID numbers and additional columns. The latter file contains multiple lines for each ID number and I need to extract all lines that match an ID from the first file. Those lines then must be printed in a new file.
Edit 1: Replaced sample files with excerpts from actual
Edit 2: Removed extra spaces that were in excerpt, but not actual file. Files likely need to be sanitized in some way, but how is unclear.
file1:
AT1G56430
AT3G55190
AT3G22880
file2:
AT1G01010|GO:0043090|RCA
AT1G56430|GO:0010233|IGI
AT1G56430|GO:0009555|IGI
AT1G56430|GO:0030418|IGI
expected output
AT1G56430|GO:0010233|IGI
AT1G56430|GO:0009555|IGI
AT1G56430|GO:0030418|IGI
[[
I have tried:
awk -F'|' 'NR==FNR{c[$1$2]++;next};c[$1$2] > 0' file1 file2 > output.txt
and:
grep -Ff file2 file1 > output.txt
I’m aware that there are many somewhat similar questions posted in these forums and others. However, these don’t mention how the output is handled… nor do they mention duplicates. I’ve tried solutions from 4 of them, have been messing with this for many hours and keep getting the same problem: a blank output file.
I’m new to awk and I greatly appreciate the help. Sorry if this is a simple problem with syntax etc; please let me know. Thanks for the help.
grep AT1G56430 file2
output? How aboutfile file1 file2
? (Could there be an issue with Windows line-endings?)grep AT1G56430 file2
appears to output the entire file, surprisingly.file file1 file2
givesfile1: ASCII text, with CR line terminators file2: ASCII text, with CR line terminators
...od -c <file1
gives...0000000 A T 1 G 5 6 4 3 0 \r A T 3 G 5 5 0000020 1 9 0 \r A T 3 G 2 2 8 8 0 \r A T
and many more lines