grepping the output of a command in an if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grepping the output of a command in an if statement
# 1  
Old 06-29-2007
grepping the output of a command in an if statement

Probably a really simple question but how do check/grep against the output of a command within an if statement ?? for example

Code:
if [ the output of `raidctl -l` has the string "no" in it ]
then
do this
else
do something else
fi

# 2  
Old 06-29-2007
er,


Code:
if grep thing
then 
   :do this
fi

# 3  
Old 06-29-2007
Code:
if raidctl -l | grep -q "string"
then
do this
else
do something else
fi

# 4  
Old 06-29-2007
try this

grep "find_it" file_name
if [ $? = 0 ]
then
echo " found"
else
echo "NOT found"
fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

2. Shell Programming and Scripting

How to grep the grant statement and output to the different files?

Hi currently I have a list of *.sql files. one of the file, terminal is Prompt Table TERMINAL; CREATE TABLE TERMINAL ( TERMINAL_ID NUMBER(8), EXCEL_TERMINAL_ID NUMBER(8), MERCHANT_ID NUMBER(8), SETTLE_TIME VARCHAR2(4 CHAR) ); COMMENT... (4 Replies)
Discussion started by: jediwannabe
4 Replies

3. Shell Programming and Scripting

Unix shell command output to a sql statement

Can i do this Say one command sed 's/:*/ /g' $summf is returning C1234 C2345 C3434 some no of rows, now this ouput i have to insert it into a DB table how do i do this?? (2 Replies)
Discussion started by: depakjan
2 Replies

4. Shell Programming and Scripting

bash case statement output help

greetings, I have a script that is taking input like this: a b c d aa bb aaa bbb ccc ddd and formating it to be like this: a b c d aa bb aaa bbb ccc ddd (4 Replies)
Discussion started by: adambot
4 Replies

5. Shell Programming and Scripting

Redirect output of print statement to file

:confused: I have a ksh script which gathers data from a file. I need to find a way to direct the output to a new file. The code looks something like this: DUP_FILE=`touch /export/.../.../dup_social_$1` while (($# > 0 )) do # Make sure the file exists if ] then print "$1: does not... (4 Replies)
Discussion started by: Muga801
4 Replies

6. Shell Programming and Scripting

Awk output to file in IF statement

Hi all, I currently have the following script in 1) which outputs to a file if the 3rd column is equal to the message_id value. This works. However what I want to do is incorporate an else statement and output to a different file if the 3rd column doesnt equal the message_id values. I tried that... (7 Replies)
Discussion started by: Donkey25
7 Replies

7. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

8. Shell Programming and Scripting

Output of both the echo statement in one line

I have script like echo -n FINISHED FEXP: ${TABLE2EXP} echo $STATUS I want the output of both the echo statement in one line How can i do this (3 Replies)
Discussion started by: scorp_rahul23
3 Replies

9. HP-UX

SQL statement output to Log file-How?

Hi all, I need to bring the message to log file.Teradat/Hp-Ux script: ----- ### Update Log Table bteq <<- EOC .run file ${SRC_DATA}/logon.txt .run file ${SRC_DATA}/dbstagebteq.txt .set format off .set foldline off all .set sidetitles off ... (1 Reply)
Discussion started by: vsubbu1000
1 Replies

10. Windows & DOS: Issues & Discussions

Want to use the output of Select statement in Unix script

Hi, I have a UNIX script which calls SQL Select statement: Now i want to use the output of that select statement within my UNIX script so as to call different shell script depending upon the output of the select statement. Can anyone help me in this regard. TIA Akhil Goel (4 Replies)
Discussion started by: akhilgoel9
4 Replies
Login or Register to Ask a Question