Results 1 to 4 of 4

Thread: How to grep multiple values at a time..

  1. #1
    Senior Member
    Join Date
    Jun 2007
    Location
    Hyderabad, AP, India
    Posts
    806
    Thanks
    44
    Thanked 55 Times in 48 Posts
    Rep Power
    13

    Default How to grep multiple values at a time..

    Hi all,
    I want to grep two or more values i gone through this link
    http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/
    but it is using or.. i mean either of the words if the grep finds it will output.. but my req is both the words should be present..

    Coming to my requirement.. i have to check all the below packages are installed or not..
    samba
    samba-swat
    system-config-samba
    samba-common
    samba-client

    depending on the packages installed i have to install remaining packages..
    Here is my code..
    Code:
    rpm -qa | grep samba
                                    if [ $? -eq 0 ]
                                            then
                                            echo "Samba package is there.. Now configuring winbind.."
                                            config_samba;
    but this code is not conforming what samba packages are installed..

    Any help on this will help a lot..
    Last edited by nixcraft; 26th March 2010 at 01:28 PM.
    Thanks,
    Surendra Kumar Anne
    Linux: Fast, friendly, flexible and .... free!
    Support Open source.
    http://www.linuxnix.com

  2. #2
    Senior Member
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    0
    Thanked 33 Times in 29 Posts
    Rep Power
    12

    Default

    use awk instead

    eg 2 conditions ANDed
    Code:
    ... | awk '/condition1/ && /condition2/'

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    0

    Default

    command 1 && command 2 && {echo "Got all" ;} || { echo "at least 1 missing";}

    - Can add as many commands between command 1 and command 2.

  4. #4
    Senior Member
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    0
    Thanked 33 Times in 29 Posts
    Rep Power
    12

    Default

    Quote Originally Posted by Mirneli View Post
    command 1 && command 2 && {echo "Got all" ;} || { echo "at least 1 missing";}

    - Can add as many commands between command 1 and command 2.
    he wants to grep multiple values using grep.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to read multiple values at a time from a file..
    By kumarat9pm in forum Shell scripting
    Replies: 3
    Last Post: 27th March 2010, 05:12 AM
  2. [Solved] How to use Bash IFS to split values by | symbol
    By raj in forum Shell scripting
    Replies: 4
    Last Post: 9th January 2010, 10:29 AM
  3. How to use arrays and its values present in one script?
    By Nishanthhampali in forum Shell scripting
    Replies: 0
    Last Post: 31st January 2008, 03:04 PM
  4. Shell scripting: How to compare float values
    By chanderbio in forum Shell scripting
    Replies: 1
    Last Post: 26th July 2007, 06:46 PM
  5. How can I Update the XML Tag Values using Shell Script
    By Mithun_Kamath in forum Shell scripting
    Replies: 1
    Last Post: 25th January 2007, 01:29 AM

Posting Permissions

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