Change Shell script variable value inside AWK conditional block

aejaz

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.
James Brown

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Shell script change directory with variable

From Dev

Shell script - awk extract block from file into array

From Dev

Value not assigned to variable in shell script

From Dev

shell script for awk print divide value with 1024

From Dev

Conditional show text block in .docx using OpenTBS based on variable value

From Dev

Awk print is not working inside bash shell script

From Dev

LESS conditional variable change inside mixin

From Dev

Store value to variable in Shell script

From Dev

Modify a shell variable inside awk block of code

From Dev

Conditional in shell script

From Dev

Exporting a Path Variable inside a shell script

From Dev

Makefile: How to use a loop value inside a shell block

From Dev

Value not assigned to variable in shell script

From Dev

get variable's value in if conditional Batch Script

From Dev

Assigning "awk" or "nawk" to a variable in a shell script

From Dev

Shell Script: creating a variable with options inside

From Dev

Awk: if and conditional statement in same block

From Dev

awk variable inside a shell function

From Dev

Using if and shell variables inside an awk script

From Dev

linux|awk|shell script block deletion

From Dev

How to change the value of $SHELL variable?

From Dev

Change variable value inside a variable in PHP

From Dev

Exporting a Path Variable inside a shell script

From Dev

How to retain the value of a variable inside for loop in shell script

From Dev

Change the value of a variable inside a function

From Dev

Use shell variable inside a pattern in awk

From Dev

my shell script inside shell script not getting int variable

From Dev

awk or shell script to change format of a tab delimited file

From Dev

Change a variable in a shell script loop

Related Related

  1. 1

    Shell script change directory with variable

  2. 2

    Shell script - awk extract block from file into array

  3. 3

    Value not assigned to variable in shell script

  4. 4

    shell script for awk print divide value with 1024

  5. 5

    Conditional show text block in .docx using OpenTBS based on variable value

  6. 6

    Awk print is not working inside bash shell script

  7. 7

    LESS conditional variable change inside mixin

  8. 8

    Store value to variable in Shell script

  9. 9

    Modify a shell variable inside awk block of code

  10. 10

    Conditional in shell script

  11. 11

    Exporting a Path Variable inside a shell script

  12. 12

    Makefile: How to use a loop value inside a shell block

  13. 13

    Value not assigned to variable in shell script

  14. 14

    get variable's value in if conditional Batch Script

  15. 15

    Assigning "awk" or "nawk" to a variable in a shell script

  16. 16

    Shell Script: creating a variable with options inside

  17. 17

    Awk: if and conditional statement in same block

  18. 18

    awk variable inside a shell function

  19. 19

    Using if and shell variables inside an awk script

  20. 20

    linux|awk|shell script block deletion

  21. 21

    How to change the value of $SHELL variable?

  22. 22

    Change variable value inside a variable in PHP

  23. 23

    Exporting a Path Variable inside a shell script

  24. 24

    How to retain the value of a variable inside for loop in shell script

  25. 25

    Change the value of a variable inside a function

  26. 26

    Use shell variable inside a pattern in awk

  27. 27

    my shell script inside shell script not getting int variable

  28. 28

    awk or shell script to change format of a tab delimited file

  29. 29

    Change a variable in a shell script loop

HotTag

Archive