Click to See Complete Forum and Search --> : Shell Scripting question


nickflind
January 23rd, 2008, 07:15 AM
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

PeejAvery
January 23rd, 2008, 07:30 AM
[ moved ]

olivthill
January 23rd, 2008, 08:05 AM
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:
a_filename=`echo ${i} | awk '{printf("foo%03d.txt", $1)}'`
In the same way, you can have:
var1=`tqladmin -info | sed '1,2d'`
var2=`echo ${var1}|awk '{ if (($2 != "LOADER") && ($2 != "ALARMER") && ($2 != "DBA") && ($2 != "LAUNCHER")) print}'`(not tested)

nickflind
January 23rd, 2008, 09:28 AM
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:
a_filename=`echo ${i} | awk '{printf("foo%03d.txt", $1)}'`
In the same way, you can have:
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