I have two files
$cat file 1 Index1 annotation1 abcd Index2 annotation2 efgh Index3 annotation3 hijk Index4 annotation4 lmno Index5 annotation5 pqrs …
$cat file2 Index1 Index3 Index5
What I want to get is the list of lines from file 1 and the line afterward of each line retrieved like following.
Index1 annotation1 abcd Index3 annotation3 hijk Index5 annotation5 pqrs
My current solution is to use grep and its ‘file’ flag
grep -A 1 --file="file2" file1 | awk '!/--/'
But I was wondering if there is more elegant solutions to this. The current solution takes a long time when the files are huge
1 Answer