can i exectue a command stored in a variable.it goes like this


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers can i exectue a command stored in a variable.it goes like this
# 1  
Old 11-01-2007
can i exectue a command stored in a variable.it goes like this

hi

the code i ve written is as follows:
command="egrep ',100,|,200,' | wc -l"
count =`cat trial.txt | $command`
echo "$count"
the contents of
trial.txt is :
000,100,200,300,
001,200,100,201,
002,200,100,400,


i need to get the count using the command stored in a variable and using it to get the count.
Can someone help me with this?Smilie
# 2  
Old 11-01-2007
what file are you searching with egrep?
# 3  
Old 11-01-2007
cat trial.txt | egrep ',100,|,200,' | wc -l| more
3
try an alias

alias command="egrep ',100,|,200,' | wc -l"

cat trial.txt |command |more
3
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Run command stored in variable

Hi, I have a shell script where I have to connect t oracle database. I have to store the command in a variable and then run the command through the variable.The OS is solaris 10 and the shell is bash.pls help when I run the command it doesnot work.Thanks. if CONNECT= "sqlplus... (4 Replies)
Discussion started by: Rossdba
4 Replies

2. Shell Programming and Scripting

Variable being stored with additional characters

I am trying to store a string value to a temporary variable within my script. When I run the command manually it returns the expected value, but from the script an additional "\r" is at the end. tCurrentStatus=`cat ${tPC_status} | grep 'Current status' | awk '{print $NF}'` output: cat... (1 Reply)
Discussion started by: jxrst
1 Replies

3. UNIX for Dummies Questions & Answers

List of All Users Stored in Variable

I'm trying to get a list of all users on the system, store the list in a variable, then find all the files of a certain extension owned by each of the users. The command I use to get the list is getent passwd | cut -d: -f1 | sortand this works just fine. However, if I try to store it in a... (1 Reply)
Discussion started by: hobscrk777
1 Replies

4. Red Hat

How to check values stored in variable?

hey, i have stored values of query like this val_2=$( sqlplus -s rte/rted1@rel75d1 << EOF set heading off select source_id from cvt_istats where istat_id > $val_1; exit EOF ) echo $val_2 now , val_2 has five values displayed like this 1 2 3 4 5 what i have to do is to check the... (1 Reply)
Discussion started by: ramsavi
1 Replies

5. Shell Programming and Scripting

Function returns a value but cannot be stored in other variable

I need help to store the value returned from the function to one variable and then use that variable. PREVIOUS_DATE_FUNCTION() { date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

6. Shell Programming and Scripting

Variable not found error for a variable which is returned from stored procedure

can anyone please help me with this: i have written a shell script and a stored procedure which has one OUT parameter. now i want to use that out parameter as an input to the unix script but i am getting an error as variable not found. below are the unix scripts and stored procedure... ... (4 Replies)
Discussion started by: swap21783
4 Replies

7. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

8. Linux

Incrementing the date stored in the variable

Hi all, I have a variable with date as 20080831 . Now I want to increment it as 20080901 and so on.Is there any command for this. Please help me. thanks rameez (1 Reply)
Discussion started by: rameezrajas
1 Replies

9. Shell Programming and Scripting

Increment variable stored in a file

Hi, I want to write a perl script, which will increment number stored in file. I want to do this without any file handles. I think we have to use some UNIX commands. I am not sure how to do this with file handles. Thanks, (1 Reply)
Discussion started by: solitare123
1 Replies

10. Shell Programming and Scripting

how to get the string stored in a variable in a line???

Hi all, I want to search for a data type in a line.For this in a loop i am checking for $DATA_TYPE in a line using grep.But grep is not able to find when i give this. Can any one tell me how to check string in $DATA_TYPE variable in line usign grep (or) any other way to do the above task. ... (4 Replies)
Discussion started by: jisha
4 Replies
Login or Register to Ask a Question