I have two text files. Text-file-1 contains strings (one string per line);
C 010
C 020
C 024
.
.
.
Text-file-2 contains data in following format;
C 005 Carbon
D Carbon 1
D Carbon 2
D Carbon 3
D Carbon 4
C 010 Hydrogen
D Hydrogen 1
D Hydrogen 2
C 017 Oxygen
D Oxygen 1
C 020 Nitrogen
D Nitrogen 1
D Nitrogen 2
D Nitrogen 3
C 024 Sulphur
D Sulphur 1
D Sulphur 2
.
.
.
Text-file-1 contains 30 lines but Text-file-2 contain huge data, and in the same format as I mentioned. I can grep the text in Text-file-2 found in Text-file-1 using following command;
awk 'NR==FNR { A[$2]=1; next }; A[$2]' Text-file-1 Text-file-2 > filename
Output for this script
C 010 Hydrogen
C 020 Nitrogen
C 024 Sulphur
.
.
.
My Desired output is;
C 010 Hydrogen
D Hydrogen 1
D Hydrogen 2
C 020 Nitrogen
D Nitrogen 1
D Nitrogen 2
D Nitrogen 3
C 024 Sulphur
D Sulphur 1
D Sulphur 2
.
.
.
Now, I need an extension of this command, which could print all lines (starting with "D"), including and after this line. All lines in Text-file-2 are starting with a letter (C or D). This letter is not useful for me, but I kept it. Kindly help.