Не могли бы вы попробовать следующее, это даст результаты в том же порядке, в котором $1
происходит в Input_file1.
awk '
BEGIN{
s1="\""
}
FNR==NR{
a[$0]
next
}
(int($1) in a){
system("grep -A2 " s1 $0 s1 OFS FILENAME)
}
' Input_file1 Input_file2
Объяснение: Добавление пояснения к приведенному выше коду.
awk ' ##Starting awk program here.
BEGIN{ ##Starting BEGIN section of code here.
s1="\"" ##Creating a variable named s1 whose value is "
} ##Closing BEGIN section of awk code here.
FNR==NR{ ##Checking condition if FNR==NR, which will be only TRUE when Input_file1 is being read.
a[$0] ##Creating an array named a whose index is $0.
next ##next will skip all further statements from here.
} ##Closing BLOCK for FNR==NR condition here.
(int($1) in a){ ##Checking condition if integer value of $1 is present in array a then do following.
system("grep -A2 " s1 $0 s1 OFS FILENAME) ##Using system command to run grep command which will print 2 lines after match of current line in current Input_file name passed to grep by FILENAME variable of awk.
} ##Closing BLOCK of condition.
' Input_file1 Input_file2 ##Mentioning Input_file names here.
Вывод будет следующим.
4.999286 12.669064 0.000000
5.999343 12.753258 0.000000
6.999401 12.654514 0.000000
7.999458 12.774485 0.000000
8.999515 12.662147 0.000000
9.999572 12.700071 0.000000
8.999515 12.662147 0.000000
9.999572 12.700071 0.000000
10.999629 12.717721 0.000000