What I want to achieve
- Search a word next to a specific phrase in a file with the Linux shell command
How to tackle
Use the grep command and the awk command.
$ grep -w "search_word" file_name | awk '{print $2}'
Explanations
- by the
-woptiongrepmatches only whole words, preventing partial matches -
{print $2}withawkprints the second word on each line
Top comments (0)