on-internet
← Community

Print specific lines after a text present in another text file

Stack Overflow ·

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-

Comments

Sign in or sign up to comment and upvote.

No comments yet.