CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2008
    Posts
    2

    Shell Scripting question

    I have a question concerning the following code I have written:

    tqladmin -info commands returns a list that I store in the myScript file.
    Then I start processing this list but I keep creating new files in order to do so, myScript.tmp, myScript1.tmp etc...
    Is there any way I can avoid creating new files and work with variables?

    tqladmin -info > ~/myScript.tmp
    cat ~/myScript.tmp | sed '1,2d' > ~/myScript1.tmp
    awk '{ if (($2 != "LOADER") && ($2 != "ALARMER") && ($2 != "DBA") && ($2 != "LAUNCHER")) print}' ~/myScript1.tmp > ~/myScript2.tmp

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Shell Scripting question

    [ moved ]
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: Shell Scripting question

    You can assign the result of your commands to a variable using back quotes. For instance, in order to have a formatted string you can have:
    Code:
    a_filename=`echo ${i} | awk '{printf("foo%03d.txt", $1)}'`
    In the same way, you can have:
    Code:
    var1=`tqladmin -info | sed '1,2d'`
    var2=`echo ${var1}|awk '{ if (($2 != "LOADER") && ($2 != "ALARMER") && ($2 != "DBA") && ($2 != "LAUNCHER")) print}'`
    (not tested)

  4. #4
    Join Date
    Jan 2008
    Posts
    2

    Re: Shell Scripting question

    Quote Originally Posted by olivthill
    You can assign the result of your commands to a variable using back quotes. For instance, in order to have a formatted string you can have:
    Code:
    a_filename=`echo ${i} | awk '{printf("foo%03d.txt", $1)}'`
    In the same way, you can have:
    Code:
    var1=`tqladmin -info | sed '1,2d'`
    var2=`echo ${var1}|awk '{ if (($2 != "LOADER") && ($2 != "ALARMER") && ($2 != "DBA") && ($2 != "LAUNCHER")) print}'`
    (not tested)
    Hi olivthill,
    thank you for your answer,

    I tried to copy the file in a variable like you indicate but the problem is that the tqladmin command returns a list of variables like below:

    13630 PHAT NPRDB 13597
    7565 NVAG NPRDB 19862 npru
    8651 ASOF NPRDB 14920 npru

    If I move this output to a variable, the list will be lost and I wont be able to process it with awk.
    The variable will be like this: 13630 PHAT NPRDB 13597 7565 NVAG NPRDB 19862 npru 8651 ASOF NPRDB 14920 npru
    Last edited by nickflind; January 23rd, 2008 at 10:31 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured