Find the answer to your Linux question:
Results 1 to 2 of 2
Hey all, I'm running into a problem when I try to set a variable to an awk output in c-shell. Right now my command is Code: set STR_MSG_TYPE = `awk ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    2

    Setting variables in c-shell

    Hey all, I'm running into a problem when I try to set a variable to an awk output in c-shell. Right now my command is

    Code:
    set STR_MSG_TYPE = `awk -F\{ '/msg_type/ {print $2}' <filename> | tr -d }'/''*' `
    I then run echo to see what the output is and it returns blank, however, when I run the same awk command from the command line, I get an actual output of "MT-715". Am I setting my variable incorrectly? I do something similar using the date command to set a STR_DATE variable earlier in the code and it works fine and I use the same syntax. Help oh wise unix gurus!

    Thanks!

  2. #2
    Just Joined!
    Join Date
    Jul 2010
    Posts
    53
    first thing i see is your -F\
    the \ is used to pass control characters so or if you are wanting the field separator to be a '\' you will need to supply \\

    can test that with something like below:

    $ set xx = `awk -F\\ '{print $2}'`
    a \ b
    $ echo $xx
    b

    also notice the actual awk script is surrounded by single quotes - this avoids the shell trying to interpret $ inside the script.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...