list.txt GETID_17049_knownids_1/2_Confidence_0.625_Length_2532 GETID_9248_knownids_6/10_Confidence_0.439_Length_2474 GETID_11084_knownids_3/3_Confidence_0.600_Length_1451 GETID_15916_knownids_10/11_Confidence_0.324_Length_1825sample1.txt>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532sampletextforsample1sampletextforsample1sampletextforsample1>GETID_18457_knownids_1/2_Confidence_0.625_Length_2532sample2textforsample1sample2textforsample1sample2textforsample1sample2textforsample1sample2.txt>GETID_11084_knownids_3/3_Confidence_0.600_Length_1451sampletextforsample2sampletextforsample2>GETID_67838_knownids_3/3_Confidence_0.600_Length_1451sample2textforsample2sample2textforsample2sample3.txt>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532sampletextforsample3sampletextforsample3sampletextforsample3>GETID_15916_knownids_10/11_Confidence_0.324_Length_1825sample2textforsample3sample2textforsample3output.txt>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532sampletextforsample1sampletextforsample1sampletextforsample1>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532sampletextforsample3sampletextforsample3sampletextforsample3>GETID_11084_knownids_3/3_Confidence_0.600_Length_1451sampletextforsample2sampletextforsample2>GETID_15916_knownids_10/11_Confidence_0.324_Length_1825sample2textforsample3sample2textforsample3I want to read each line from list.txt (by capturing bracketed values (GETID_{17049}knownids{1/2}_Confidence_1.0_Length_{2532}) and compare with sample1.txt, sample2.txt, sample3.txt has multiple line and print the contents (output.txt) from these files when it is matched with list.txt. The output should contain exact match to list.txt. Any help in awk/sed/perl is appreciated.
Getting data from matching list
sed;awk;perl
If you slightly modify the solution provided by Gilles in this question (also referred to by jw013), you can get the effect you ask for, except that the order is based on the input sequence and not identical to output.txt listed in your question:awk -v patterns_file=list.txt 'BEGIN {  while (getline < patterns_file)    patterns_array[> $0] = 1  close(patterns_file)}$0 in patterns_array { print; getline; print }' sample[1-3].txtOutput:>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532sampletextforsample1>GETID_11084_knownids_3/3_Confidence_0.600_Length_1451sampletextforsample2>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532sampletextforsample3>GETID_15916_knownids_10/11_Confidence_0.324_Length_1825sample2textforsample3EditTo make this work with multi-line records use an appropriate record separator (RS), in your case setting it to: greater-than at beginning of file (^>) or new-line followed by greater-than (\n>) or new-line at the end of the file (\n$) seem like good choices based on the input provided.Something like this should work:awk -v patterns_file=patterns.txt 'BEGIN {  while (getline < patterns_file)     patterns_array[$0] = 1  close(patterns_file)  RS=^>|\n>|\n$}$1 in patterns_array { print > $0 }' sample[1-3].txtEdit 2To output each record only once, delete it from patterns_array after output:awk -v patterns_file=patterns.txt 'BEGIN {  while (getline < patterns_file)     patterns_array[$0] = 1  close(patterns_file)  RS=^>|\n>|\n$}$1 in patterns_array { print > $0; delete patterns_array[$1] }' sample[1-3].txt