I've been playing around with a few regular expressions for half an hour now and I'm stumped on what to do. Here's the string I want to apply the regex to:
./crafty_base.gnu3 < crafty.in > crafty.out 2> crafty.err
What I want to do is extract everything between the <, > and 2>. I've managed to grab everything but crafty.out now. Here's my bash script:
Code:
# exec_target contains the initial string I want to perform the regex on
exec_in=$echo $(echo exec_target | sed 's/.*<//g') | sed 's/>.*//g')
exec_out=$(echo exec_target | sed 's/.*?^2>//g')
exec_err=$(echo exec_target | sed 's/.*2>//g')
echo "TARGET: $exec_target"
echo "INPUT: $exec_input"
echo "OUTPUT: $exec_output"
echo "ERROR: $exec_err"
And the output of this script:
Code:
TARGET: ./crafty_base.gnu3
INPUT: crafty.in
OUTPUT: ./crafty_base.gnu3 < crafty.in > crafty.out 2> crafty.err
ERROR: crafty.err
What I want to tell sed is "eat up everything that occurs before the first >", but no matter what I've tried it always eats up everything before the last ">". I tried to fix this by saying that the 2 character can not preceed the > but that doesn't seem to be working. And setting .* to be ungreedy causes nothing to be eaten at all.
I've tried googling, reading the sed manpage, and I just can't find a solution. Does anyone know how I can do this?
Oh and FYI: I can't do something like use the < for solving this problem, because I'm using these regexes for multiple strings, all of which <, > and 2> are completely optional.