|
-
January 23rd, 2008, 08:15 AM
#1
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
-
January 23rd, 2008, 08:30 AM
#2
Re: Shell Scripting question
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 23rd, 2008, 09:05 AM
#3
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)
-
January 23rd, 2008, 10:28 AM
#4
Re: Shell Scripting question
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|