We'd like to import code between two strings and put them in an variable.
We have:
job=1
listen="$(awk -v a="BEGIN-$job" -v e="END-$job" '/BEGIN {print a}/{p=1;next} /BEGIN {print e}/{p=0;exit} p' whatsthat.file)"
whatsthat.file (edited):
BEGIN-1
echo "some code"
END-1
BEGIN-2
echo "next job"
END-2
Final result for variable $listen should be:
echo "some code"
But the command above leaves $listen empty.
/BEGIN {print a}/for? Do you know what/···/means?awk /BEGIN/{p=1;next} /END/{p=0;exit} p' whatsthat.fileand only BEGIN and END in whatsthat.file it works. So the // are for checking the code between.