How to pull second line past keyword in a file into a shell variable.
I have a file which contains a keyword im looking for.
I need to pull the second line past the keyword into a shell variable. Any suggestions on how to do this? |
I usually do things the brute force way first and then figure out something more refined.
Or not. For something like this I may double grep, or use grep and cut. For instance, I'd grep to find that line, providing it is a unique line in the file. And then I'd use cut to remove all before or after. Another alternative is if there are delimiters, I'd use awk to treat it as column data and then select the correct column I needed. Really what I'd do is go so far, and then web search for things like "grabbing the second field in a string using linux command line" and find examples and then choose the most comfortable one for me, that being the one I can best understand. |
Code:
Variable=$(grep -A2 <keyword> file | tail -1) Have fun! |
Quote:
|
Go TeamLQ!
Quote:
So, we don't have to feel like "support"? You're Welcome. |
All times are GMT -5. The time now is 05:20 AM. |