Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Regular Expression / Command Chaining / One liner

  1. #1
    Join Date
    Jun 2008
    Beans
    62

    Regular Expression / Command Chaining / One liner

    I need to check, whether few packages are installed in the system or not. There are around 35 package names which is there in a text files called "check-pkgs". All the package names are mentioned in line by line.

    How can i use a simple online command, to check whether these mentioned packages are installed in my system.

    i tried the following, but didnt worked.

    $ dpkg -l | grep `cat check-pkgs`

    according to my idea, this command should work!!! but its not working for me, So, can u plz explain to me why this is not working in this situation.


    Thanks in advance...

    NOTE: I had posted around 5 - 7 times, asking different questions, but i didnt received any answers for it. Hope this time, i will have one from you...

    KMR

  2. #2
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Regular Expression / Command Chaining / One liner

    Try:

    Code:
    dpkg -l | grep -f check-pkgs
    Don't try to make something "fast" until you are able to quantify "slow".

  3. #3
    Join Date
    Oct 2007
    Location
    United Kingdom
    Beans
    762
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Regular Expression / Command Chaining / One liner

    try

    Code:
    dpkg -l | grep -f check-pkgs
    "Python, the language that wraps itself around a problem to squeeze out a solution, swallowing it whole."
    Linux user number #14284
    "A journey of a thousand miles begins with a single step." - Confucius.

  4. #4
    Join Date
    Jun 2008
    Beans
    62

    Re: Regular Expression / Command Chaining / One liner

    Thanks for your replies,


    And this command is working fine. But now i have one more doubt... from the output, i cant understand which are all the packages is actually installed and which are not...

    this is the output when i run individually;

    Code:
    kmr@system5:~$ dpkg -l | grep libxv1
    kmr@system5:~$ dpkg -l | grep libxss1
    kmr@system5:~$ dpkg -l | grep libxext6
    kmr@system5:~$ dpkg -l | grep libx11-6
    kmr@system5:~$ dpkg -l | grep libstdc++6
    ii  libstdc++6                                 4.2.3-2ubuntu7              The GNU Standard C++ Library v3
    ii  libstdc++6-4.2-dev                         4.2.3-2ubuntu7              The GNU Standard C++ Library v3 (development
    kmr@system5:~$ dpkg -l | grep libqt4-gui
    kmr@system5:~$ dpkg -l | grep libqt4-core
    kmr@system5:~$ dpkg -l | grep libgcc1
    ii  libgcc1                                    1:4.2.3-2ubuntu7            GCC support library
    kmr@system5:~$ dpkg -l | grep libc6
    ii  libc6                                      2.7-10ubuntu3               GNU C Library: Shared libraries
    ii  libc6-dev                                  2.7-10ubuntu3               GNU C Library: Development Libraries and Hea
    ii  libc6-i686                                 2.7-10ubuntu3               GNU C Library: Shared libraries [i686 optimi
    kmr@system5:~$ dpkg -l | grep libasound2
    see this, from this i cant understand, which one among the files are installed. is there any tricky way to find out... i guess we need a script itself. if so, can anybody point to a script.

    Code:
    kmr@system5:~$ dpkg -l | grep -f check-depends 
    ii  libc6                                      2.7-10ubuntu3               GNU C Library: Shared libraries
    ii  libc6-dev                                  2.7-10ubuntu3               GNU C Library: Development Libraries and Hea
    ii  libc6-i686                                 2.7-10ubuntu3               GNU C Library: Shared libraries [i686 optimi
    ii  libgcc1                                    1:4.2.3-2ubuntu7            GCC support library
    ii  libstdc++6                                 4.2.3-2ubuntu7              The GNU Standard C++ Library v3
    ii  libstdc++6-4.2-dev                         4.2.3-2ubuntu7              The GNU Standard C++ Library v3 (development
    kmr@system5:~$ cat check-depends 
    libasound2
    libc6
    libgcc1
    libqt4-core
    libqt4-gui
    libstdc++6
    libx11-6
    libxext6
    libxss1
    libxv1

    NOTE: i didnt get an answer why my command dpkg -l | grep `cat check-depends` didnt worked like this grep -f.

    Thanks for ur help...
    Last edited by rahmath; August 8th, 2008 at 06:13 PM.

  5. #5
    Join Date
    Apr 2008
    Location
    United Kingdom
    Beans
    84
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Regular Expression / Command Chaining / One liner

    if the line starts with "ii" that means the package is installed.

    I would guess that the way you put your command meant it was searched for the string output by cat, which inevitably won't exist if you've put more than one package in the file. Just guessing though.

  6. #6
    Join Date
    Jun 2008
    Beans
    62

    Re: Regular Expression / Command Chaining / One liner

    damo, thx for ur reply.

    I know "ii" means it is installed. the problem here is, i cant understand, which among the packages in my check-depend files are installed and which are not installed.

    Is there any way to know that... like

    Package 1 - installed
    Package 2 - installed
    Package 3 - not installed
    and so on... based on the no of lines in the check-depends file,.

  7. #7
    Join Date
    Aug 2005
    Beans
    380

    Re: Regular Expression / Command Chaining / One liner

    Scripts based on grep in this way may run into false positives, if you aren't careful. For example, you will get a false positive for an entry "foo-bar" in check-pkgs if your system has a package called "foo-bar-bazz" installed.

  8. #8
    Join Date
    Jun 2008
    Beans
    62

    Re: Regular Expression / Command Chaining / One liner

    any idea???

  9. #9
    Join Date
    Oct 2007
    Location
    United Kingdom
    Beans
    762
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Regular Expression / Command Chaining / One liner

    Quote Originally Posted by rahmath View Post
    NOTE: i didnt get an answer why my command dpkg -l | grep `cat check-depends` didnt worked like this grep -f.
    Because it's simply wrong. `cat check-depends` will put all the lines in "check-depends" onto the command line. However, the syntax for grep doesn't allow you to pass multiple strings to search for on the command line like that. You have to pass a single regular expression that will match them, e.g. probably using | symbol, or you have to use "-f <filename>". Read the "man" page.
    Last edited by ByteJuggler; August 9th, 2008 at 03:55 PM.
    "Python, the language that wraps itself around a problem to squeeze out a solution, swallowing it whole."
    Linux user number #14284
    "A journey of a thousand miles begins with a single step." - Confucius.

  10. #10
    Join Date
    Aug 2005
    Beans
    380

    Re: Regular Expression / Command Chaining / One liner

    Something like
    Code:
    apt-cache  policy `cat check-pkgs` | grep -B1 Installed
    should give you output like
    Code:
    tomboy:
      Installed: 0.11.1-0ubuntu1
    --
    nautilus:
      Installed: 1:2.22.3-0ubuntu2
    --
    aap-doc:
      Installed: (none)

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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