I have 2 text files with several lines. I want to delete all lines in file 1 that doesn't have the text in file 2 example:
file1
2345678 sdfsdfsdfsf 10.00 dirfkdkfsdf XP
2345679 sdfsdfsdfsf 10.00 dirfkdkfsdf XP
2345680 sdfsdfsdfsf 10.00 dirfkdkfsdf XP
2345681 sdfsdfsdfsf 10.00 dirfkdkfsdf XP
2345682 sdfsdfsdfsf 10.00 dirfkdkfsdf XP
file2
2345678
2345679
I need to end up with this in file1
2345678 sdfsdfsdfsf 10.00 dirfkdkfsdf XP
2345679 sdfsdfsdfsf 10.00 dirfkdkfsdf XP
I have to do this in a bash script, using sed, awk, whatever. I have tried this but doesn't work
Prints all records in file1
awk 'NR==FNR{a[$0];next} !($0 in a)' file2 file1
Only prints file2
awk 'NR!=FNR{a[$0];next} !($0 in a)' file2 file1