I want to use a sed capture group to get the value of an option from a list of command line arguments. What would the sed string be to be able to get the value settings.conf associated with the -f flag for the string below:
./make-certs.sh client -s int -f settings.conf -o certs/int_env
I have tried sed -E s:.* -f (.*) .*:/1: but this sed string, for this example, would give settings.conf -0. I realise the problem is .* is greedy but how would I make this non-greedy using sed?
>Solution :
With GNU sed, an extended regular expression (-E) and with a backreference:
sed -E 's/.*-f ([^ ]+).*/\1/' file
Output:
settings.conf
See: The Stack Overflow Regular Expressions FAQ