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

Thread: Use regex in zypper

  1. #1
    Join Date
    Nov 2013
    Location
    Canadiana
    Posts
    461

    Default Use regex in zypper

    Is it possible to use regex in zypper? The reason I asked this is because sometimes zypper se lists too many packages and reading through them is annoying. It would be nice if I could just search for a regex and zypper could recognize them and substitute as needed. I know you can use awk and do stuff like this (thanks Jetchisel):
    Code:
    awk '$2 ~ /^name$/' < <(zypper se name)
    But this is 'ugly' and it would be great if you could do it with just zypper. So any way to do it?

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,274

    Default Re: Use regex in zypper

    Quote Originally Posted by alanbortu View Post
    Is it possible to use regex in zypper? The reason I asked this is because sometimes zypper se lists too many packages and reading through them is annoying. It would be nice if I could just search for a regex and zypper could recognize them and substitute as needed. I know you can use awk and do stuff like this (thanks Jetchisel):
    Code:
    awk '$2 ~ /^name$/' < <(zypper se name)
    But this is 'ugly' and it would be great if you could do it with just zypper. So any way to do it?
    I should say the man page of zypper shows many options to refine a search. Wildcards are mentioned, case sensitivety, match-all/any/substrings/words/exact. Does this realy n provide you witjh thh wanted output?
    Henk van Velden

  3. #3

    Default Re: Use regex in zypper

    Quote Originally Posted by hcvv View Post
    I should say the man page of zypper shows many options to refine a search. Wildcards are mentioned, case sensitivety, match-all/any/substrings/words/exact. Does this realy n provide you witjh thh wanted output?
    My man page (13.1) says
    If the search string is enclosed in '/', for example $ zypper se '/^k.*e$/', it's interpreted as a regular expression.
    And "zypper se -h" says
    If a search string is enclosed in '/', it's interpreted as a regular expression.
    But it doesn't seem to work -> https://bugzilla.novell.com/

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,274

    Default Re: Use regex in zypper

    The -h option is not in the 12.3 man page.

    Thus we have again a case were potential helpers are left in distress because the OP does not tell which version of openSUSE he uses.
    Henk van Velden

  5. #5
    Join Date
    Nov 2013
    Location
    Canadiana
    Posts
    461

    Default Re: Use regex in zypper

    Quote Originally Posted by hcvv View Post
    The -h option is not in the 12.3 man page.

    Thus we have again a case were potential helpers are left in distress because the OP does not tell which version of openSUSE he uses.
    Shoot sorry, I made it at like 2 am, wasnt thinking clear, I use 13.1.

    But thank you I will try it out.

    Edit: And it works, thank you both so much, I did try reading the manpage but probably wasnt thinking straight and missed it.

  6. #6

    Default Re: Use regex in zypper

    Quote Originally Posted by alanbortu View Post
    Shoot sorry, I made it at like 2 am, wasnt thinking clear, I use 13.1.

    But thank you I will try it out.

    Edit: And it works, thank you both so much, I did try reading the manpage but probably wasnt thinking straight and missed it.
    Run this on your 13.1
    man zypper | grep regex

    man zypper | awk '/regex/'

    and then enjoy reading the output

    jetchisel@OSSE:~> man zypper | grep regex
    <standard input>:1001: warning: numeric expression expected (got `)')
    <standard input>:1003: warning: numeric expression expected (got `)')
    <standard input>:1010: warning: numeric expression expected (got `)')
    <standard input>:1027: warning: numeric expression expected (got `)')
    <standard input>:1032: warning: numeric expression expected (got `)')
    <standard input>:1036: warning: numeric expression expected (got `)')
    <standard input>:1045: warning: numeric expression expected (got `)')
    <standard input>:1054: warning: numeric expression expected (got `)')

  7. #7
    Join Date
    Nov 2013
    Location
    Canadiana
    Posts
    461

    Default Re: Use regex in zypper

    Quote Originally Posted by jetchisel View Post
    man zypper | grep regex

    man zypper | awk '/regex/'

    jetchisel@OSSE:~> man zypper | grep regex
    <standard input>:1001: warning: numeric expression expected (got `)')
    <standard input>:1003: warning: numeric expression expected (got `)')
    <standard input>:1010: warning: numeric expression expected (got `)')
    <standard input>:1027: warning: numeric expression expected (got `)')
    <standard input>:1032: warning: numeric expression expected (got `)')
    <standard input>:1036: warning: numeric expression expected (got `)')
    <standard input>:1045: warning: numeric expression expected (got `)')
    <standard input>:1054: warning: numeric expression expected (got `)')
    Any idea why this happens? I tried the term 'search' on the zypper man page and it gave me this SUSE Paste. I also tried these two commands and they worked fine with no error.
    Code:
    man bash | grep regex
    man bash | grep 'search'
    It seems to be something with the zypper man page, any idea what it could be?
    openSUSE Leap (42.1) 64 bit
    Plasma 5.4

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,274

    Default Re: Use regex in zypper

    Strange indeed.

    It is not the grep, but the man command that generates those messages. It only generates them when the output is not formatted for the terminal.
    Code:
    henk@boven:~/test> man zypper >stdout 2>stderr
    henk@boven:~/test> cat stderr
    <standard input>:937: warning: numeric expression expected (got `)')
    <standard input>:939: warning: numeric expression expected (got `)')
    <standard input>:946: warning: numeric expression expected (got `)')
    <standard input>:961: warning [p 16, 0.8i]: cannot adjust line
    <standard input>:963: warning: numeric expression expected (got `)')
    <standard input>:968: warning: numeric expression expected (got `)')
    <standard input>:972: warning: numeric expression expected (got `)')
    <standard input>:980: warning [p 16, 5.0i]: cannot adjust line
    <standard input>:981: warning: numeric expression expected (got `)')
    <standard input>:990: warning: numeric expression expected (got `)')
    <standard input>:998: warning [p 16, 9.0i]: cannot adjust line
    <standard input>:1000: warning [p 16, 9.3i]: cannot adjust line
    henk@boven:~/test>
    Note that I have done this on openSUSE 12.3, thus the man page is different from the 13.1 one, thus the line numbers are different, but the problem is the same.
    Henk van Velden

  9. #9

    Default Re: Use regex in zypper

    Some how i am not convince that it is the man command that generates this error but zypper man page or zypper it self. (someone correct me if im wrong.)

    Code:
     
    man bash >stdout 2>stderr 
    cat stderr
    
    man sed >stdout 2>stderr 
    cat stderr
    And other executables that i have tried does not produce the same error, so alanbortu dig some more and file this bug so that Geeko can eat it already!

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,274

    Default Re: Use regex in zypper

    Quote Originally Posted by jetchisel View Post
    Some how i am not convince that it is the man command that generates this error but zypper man page or zypper it self. (someone correct me if im wrong.)
    One thing is for sure, it is not zypper itself. That program is not run when you consult it's man page.

    It is man that protests at the conversion of the man file through the ASCII driver. That is the one that does not care for bold, etc output when it runs on a VT100/ASCII type of terminal (like konsole). That means IMHO wrong formatting in that file.
    Henk van Velden

Page 1 of 2 12 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
  •