I've been using a bash script (script.sh) which uses various awk scripts (script1.awk,script2.awk) which are tailored at "runtime", by replacing values for instance. I've been looking for ways to embed them completely within the first bash script. Ideally, I would like to have a file looking like this :
################################
# AWK scripts #
################################
read -d '' scriptVariable <<'EOF'
'
{my block commands;}
'
EOF
################################
# End of AWK Scripts #
################################
awk $scriptVariable ${inputfile} # This line obviously doesn't work
instead of the traditional :
awk '{
my script commands
' ${intputfile}
Of course, I could write them to a file but the whole point is not to. Any suggestions ?
EDIT : Although dogbane answers works fine, the next problem is that with the <<'HERE' tags, newline characters are not read.I can't unquote it since, otherwise, he's trying to interpret the awk script then encountering a $ sign within (and there are). And with no newlines, I can't comment anything within the awk script (without commenting half the script when the newlines characters are being removed ...). Anyone ?
<< 'EOF'
BEGIN{#Hello
print $1
}
EOF # Is read as BEGIN{#Hello print $1} by awk; ie BEGIN{
<< EOF
BEGIN{#Hello
print $1
}
EOF #Is read correctly by awk but Bash tried to express $1 and fails
awk "$scriptVariable" ${inputfile}awk: syntax error at source line 1 context is >>> ' <<< awk: bailing out at source line 18scriptVar='...'or better yet skip the whole setting of a variable and just useawk ' ... ' file?