Find the answer to your Linux question:
Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Lakshmipathi
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.
  1. #1
    Just 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 10:15 AM. Reason: typo

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769
    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?
    hmmm.sorry I couldn't understand your question.Could please post the question,with step by step stuffs with some example?

    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

  3. #3
    Just 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!

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769
    It always ends up empty.
    I'm not really sure about sv command - I never used it. Does splitting the command - will help?

    Code:
    sv -exec "cd $testPath; build; exit" $viewName > /tmp/build.txt
    above will save build messages in output file.Then use this file with grep.
    Code:
    tempValue= grep "Build OK" /tmp/build.txt
    q-bertsuit likes this.
    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

  6. #5
    Just Joined!
    Join Date
    Oct 2012
    Posts
    10
    Perfect! That works.

    Thanks a bunch!

  7. #6
    Just Joined!
    Join Date
    Aug 2012
    Posts
    8
    "tee" command is generally used for storing intermediate values.

  8. #7
    Just Joined!
    Join Date
    Sep 2007
    Posts
    19
    Quote Originally Posted by techguru666 View Post
    "tee" command is generally used for storing intermediate values.
    You beat me to it
    something like
    Code:
    sv -exec "cd $testPath; build; exit" $viewName | tee <temp file name> | grep "Build OK"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •