Results 1 to 7 of 7
Hi!
In a script, I'm running a command that builds a program- I wan't to grep "Build OK", but I would also like to save all of the output to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-11-2012 #1Just Joined!
- Join Date
- Oct 2012
- Posts
- 10
Using grep and saving to text file
Hi!
In a script, I'm running a command that builds a program- I wan't to grep "Build OK", but I would also like to save all of the output to a txt file. At the moment I'm doing this:
tempValue=$(sv -exec "cd $testPath; build; exit" $viewName | grep "Build OK")
This saves "Build OK" to tempValue if it's found and dosn't print anything on the screen, but if it's not found, alot of text is printed.
Where should I add the "< textfile.txt" to save the output, and what can I do so that the output is not echoed if "Build OK" isn't found?
Thanks!Last edited by q-bertsuit; 10-11-2012 at 09:15 AM. Reason: typo
- 10-11-2012 #2hmmm.sorry I couldn't understand your question.Could please post the question,with step by step stuffs with some example?but if it's not found, alot of text is printed.
Where should I add the "< textfile.txt" to save the output, and what can I do so that the output is not echoed if "Build OK" isn't found?
If I'm not wrong,Since the grep fails,you are getting the complete build message is that right? Do you want to avoid that?
In case of 'Build OK' not found,you want a empty variable 'tempValue' ?First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 10-11-2012 #3Just Joined!
- Join Date
- Oct 2012
- Posts
- 10
Sorry for beeing unclear, and thanks for replying!
I would like tempValue to contain the line were it finds "Build OK". If it doesn't find it, I don't care what ends up in tempValue. (That is what is happening now. So this is working the way I want to.)
However, I would ALSO like to save the output of the sv command in a text file everytime.
When I try to save the output in a file like so:
tempValue=$(sv -exec "cd $testPath; build; exit" $viewName | grep "Build OK") > /home/desktop/testfile.txt
It always ends up empty. I also tried
tempValue=$((sv -exec "cd $testPath; build; exit" $viewName | grep "Build OK") > /home/desktop/testfile.txt)
but it gave the same result.
Thanks again!
- 10-11-2012 #4I'm not really sure about sv command - I never used it. Does splitting the command - will help?It always ends up empty.
above will save build messages in output file.Then use this file with grep.Code:sv -exec "cd $testPath; build; exit" $viewName > /tmp/build.txt
Code:tempValue= grep "Build OK" /tmp/build.txt
First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 10-11-2012 #5Just Joined!
- Join Date
- Oct 2012
- Posts
- 10
Perfect! That works.
Thanks a bunch!
- 10-11-2012 #6Just Joined!
- Join Date
- Aug 2012
- Posts
- 8
"tee" command is generally used for storing intermediate values.
- 10-12-2012 #7Just Joined!
- Join Date
- Sep 2007
- Posts
- 19


1Likes
Reply With Quote

