bash, get part of file limited by 2 strings based on grep
Solution 1:
You can't use positional parameters at all with aliases; your example only appears to assign a value whereas in reality both $1
and $2
are expanding to empty values then any "parameters" are being appended, as you can verify using set -x
:
$ set -x
$ alias test-env="echo var1 = $1 , var2 = $2"
+ alias 'test-env=echo var1 = , var2 = '
$ test-env aaa
+ echo var1 = , var2 = aaa
var1 = , var2 = aaa
If you want to pass parameters, use a shell function instead:
unalias test-env
test-env () { echo "echo var1 = $1 , var2 = $2"; }
For your main question, I'd suggest using awk in *paragraph mode" rather than grep ex. with GNU awk:
$ gawk -v RS= -v pats='aaa|hhh' '$0 ~ pats {ORS=RT; print}' file
## some info 1
aaa
bbb
ccc
## some info 3
ggg
hhh
iii