Basically I have below scenario e.g.
grep 'test: \K(\d+)' $file
=> 15grep 'test1: \K(\d+)' $file
=> 20
Is there any way to store result of both commands into a variable like with comma as separator,
Test="grep 'test: \K(\d+)' $file;grep 'test1: \K(\d+)' $file"
Answer=eval $Test
Expected output: 15,20
?
grep -Po 'test1?: \K\d+' < "$file" | paste -sd , -
. The order would be based on wheretest
andtest1
occur in the file. – Stéphane Chazelas Jan 24 '17 at 08:32grep -Po 'test...
above (assuming that's GNUgrep
)) – Stéphane Chazelas Jan 24 '17 at 08:33