I want to update mystatus shell variable to new value inside my awk code. but I guess the syntax isn't right, also I have tried declare or eval , but nothing works hi please help me with this
my code:
mystatus="resolved" -- shell variable
awk 'BEGIN { print "<table>" } -- awk code to write in new file
{
print "<tr><td>" $1 "</td><td>" $2 "</td><tr>"
if ($1=="stopped") mystatus="problem" -- change shell variable value
}
END { print "</table>" }' filestats.txt > email.html
echo $mystatus -- variabe value not getting changed.
Something like this (untested):
mystatus="resolved" # shell variable
awk '
BEGIN { print "<table>" } # awk code to write in new file
{
print "<tr><td>" $1 "</td><td>" $2 "</td><tr>"
if ($1=="stopped") {
mystatus="mystatus.txt"
print "problem" > mystatus # write to a file instead
close(mystatus)
} # I WAS MISSING I WAS MISSING I WAS MISSING I WAS MISSING I WAS MISSING
}
END { print "</table>" }' filestats.txt > email.html
read mystatus < mystatus.txt # read the status from the file
echo $mystatus # variabe value not getting changed.
Some bash purist could comment if this is any way to read from a file to a variable?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments