Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Using bash garrett@bedroom ~/Desktop/folder/project $ ./testScript.sh ../OLD-172.28.50.30-system.cfg grep: empty-ssid: No such file or directory ../OLD-172.28.50.30-system.cfg How do I get the output from grep into my SSID variable SSID=$(grep ${FILE} -o ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Dec 2010
    Posts
    122

    grep script


    Using bash

    garrett@bedroom ~/Desktop/folder/project $ ./testScript.sh ../OLD-172.28.50.30-system.cfg
    grep: empty-ssid: No such file or directory
    ../OLD-172.28.50.30-system.cfg

    How do I get the output from grep into my SSID variable

    SSID=$(grep ${FILE} -o empty-ssid)

    And when I changed the program like so:

    Code:
    # scriptName FILE, SSID, IP, Device, & Gateway
    
    FILE=${1}
    SSID=$(grep) ${FILE} -o empty-ssid
    
    echo ${FILE}
    echo ${SSID}
    #END#
    I got the following error:

    garrett@bedroom ~/Desktop/folder/project $ ./testScript.sh ../OLD-172.28.50.30-system.cfg
    Usage: grep [OPTION]... PATTERN [FILE]...
    Try 'grep --help' for more information.
    ./testScript.sh: line 5: ../OLD-172.28.50.30-system.cfg: Permission denied
    ../OLD-172.28.50.30-system.cfg

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    hi,

    do you see any difference between
    Code:
    SSID=$(grep ${FILE} -o empty-ssid)
    and
    Code:
    SSID=$(grep) ${FILE} -o empty-ssid
    ?

    btw: Use More Quotes!

  3. #3
    Linux Newbie
    Join Date
    Dec 2010
    Posts
    122
    Quote Originally Posted by watael View Post
    hi,

    do you see any difference between
    Code:
    SSID=$(grep ${FILE} -o empty-ssid)
    and
    Code:
    SSID=$(grep) ${FILE} -o empty-ssid
    ?

    btw: Use More Quotes!
    watael, so you don't know how I can get greps output into a variable?

  4. #4
    Just Joined!
    Join Date
    Jan 2009
    Location
    Minneapolis, MN
    Posts
    15
    grep <pattern> <file>

    Code:
    SSID=`grep -o empty-ssid ${FILE}`
    But that will only give you that exact pattern... so.. are you looking for the line number, surrounding text, something else?

    Code:
    vi /tmp/blah.txt
    
    
    abc xyz
    xyz
    abchedg
    viy
    Code:
    grep -o abc /tmp/blah.txt
    abc
    abc
    $ SSID=`grep -o abc /tmp/blah.txt`
    $ echo "ssid is $SSID"
    ssid is abc
    abc
    Last edited by glamiss; 08-14-2013 at 08:24 PM.

  5. #5
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    so you don't know how I can get greps output into a variable?
    answer my question.

    well, if you want to know, then look at my latest posts.

  6. #6
    Linux Newbie
    Join Date
    Dec 2010
    Posts
    122
    glamiss I have revised the code and it's still not echoing the contents of my SSID variable. It's only echoing the ${FILE} variable

    Code:
    FILE=${1}
    SSID=`grep -o empty-ssid ${FILE}`
    
    echo ${FILE}
    echo ${SSID}
    #END#

  7. #7
    Linux Newbie
    Join Date
    Dec 2010
    Posts
    122
    watael I see the difference and I tried it both ways. Never got what I was looking for.

  8. #8
    Just Joined!
    Join Date
    Jan 2009
    Location
    Minneapolis, MN
    Posts
    15
    can you paste the contents of OLD-172.28.50.30-system.cfg for us to see or is there restricted data in it you don't want people here seeing (or it's too big to bother with that here, whatever...)?

    first try, from the command line (not in the script):

    Code:
    SSID=`grep -o empty-ssid OLD-172.28.50.30-system.cfg`
    echo "ssid is ${SSID}"
    and see what that returns. you could also put something around that new variable, like

    echo "ssid is .${SSID}."
    and hopefully you don't get back

    ssid is ..

    (because that would mean SSID is null)

    But what are you trying to do with it? Just get a count of how many times empty-ssid occurs in your file? Or you just plan on using that info to maniuplate data later?

  9. #9
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    Code:
    $ echo "foo                                                                                                                                                        
    bar
    baz" > test.file
    
    $ var=$(grep 'bar' test.file)
    $ echo "$var"
    bar
    !

    could there be an alias for ``grep'', so it only prints filename?
    try:
    Code:
    alias grep

  10. #10
    Linux Newbie
    Join Date
    Dec 2010
    Posts
    122
    I'm an idiot, I was using the wrong file. Sorry about that, it's always the simple things that get me. A program will alway do what you tell it to do, never what you want it to do. Everything works as asdvertised now.

Page 1 of 2 1 2 LastLast

Posting Permissions

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