I have a long running program, my_prog that has some output that I want to parse to get two variables, $start and $end. Here’s what the output might look like:
Important data between the first set of pipes|3|a| This line is not interesting to me|5|c| ... Another line with data (at the end this time)|4|b|
In the example above, I just need:
start=3 end=b
I’m using this in a bash script. I have a feeling awk can totally solve this issue, but doing a start=$(my_prog|awk ...) will give only one variable. I guess I could do a my_array=($(my_prog|awk ...)), but that just seems messy. Also, I don’t want to put the (possibly long) output of my_prog into a variable. What’s a good, simple way to get that data? Can awk somehow write directly to the bash variables?
as @Zack wrote awk script is ok, the only improvement could be: