Genivia / ugrep

NEW ugrep 7.0: a more powerful, ultra fast, user-friendly, compatible grep. Includes a TUI, Google-like Boolean search with AND/OR/NOT, fuzzy search, hexdumps, searches (nested) archives (zip, 7z, tar, pax, cpio), compressed files (gz, Z, bz2, lzma, xz, lz4, zstd, brotli), pdfs, docs, and more
https://ugrep.com
BSD 3-Clause "New" or "Revised" License
2.63k stars 110 forks source link

Formatting the output with --format and -v gives the wrong results #85

Closed smac89 closed 3 years ago

smac89 commented 3 years ago

Before I start, I have aliased egrep to alias egrep='ugrep --sort --extended-regexp --binary --empty --hidden'.


So I wanted to find all non directories within an arch package, so I used the command:

yay -Ql olive | awk '{print $2}' | egrep --invert-match '/$'

The output was:

     3: /usr/bin/olive-editor
     6: /usr/share/applications/org.olivevideoeditor.Olive.desktop
    11: /usr/share/icons/hicolor/128x128/apps/org.olivevideoeditor.Olive.png
    13: /usr/share/icons/hicolor/128x128/mimetypes/application-vnd.olive-project.png
    16: /usr/share/icons/hicolor/16x16/apps/org.olivevideoeditor.Olive.png
    18: /usr/share/icons/hicolor/16x16/mimetypes/application-vnd.olive-project.png
    21: /usr/share/icons/hicolor/256x256/apps/org.olivevideoeditor.Olive.png
    23: /usr/share/icons/hicolor/256x256/mimetypes/application-vnd.olive-project.png
    26: /usr/share/icons/hicolor/32x32/apps/org.olivevideoeditor.Olive.png
    28: /usr/share/icons/hicolor/32x32/mimetypes/application-vnd.olive-project.png
    31: /usr/share/icons/hicolor/48x48/apps/org.olivevideoeditor.Olive.png
    33: /usr/share/icons/hicolor/48x48/mimetypes/application-vnd.olive-project.png
    36: /usr/share/icons/hicolor/512x512/apps/org.olivevideoeditor.Olive.png
    38: /usr/share/icons/hicolor/512x512/mimetypes/application-vnd.olive-project.png
    41: /usr/share/icons/hicolor/64x64/apps/org.olivevideoeditor.Olive.png
    43: /usr/share/icons/hicolor/64x64/mimetypes/application-vnd.olive-project.png
    45: /usr/share/metainfo/org.olivevideoeditor.Olive.appdata.xml
    48: /usr/share/mime/packages/org.olivevideoeditor.Olive.xml
    51: /usr/share/olive-editor/effects/boxblur.frag
    52: /usr/share/olive-editor/effects/boxblur.xml
    53: /usr/share/olive-editor/effects/bulge.frag
    54: /usr/share/olive-editor/effects/bulge.xml
    55: /usr/share/olive-editor/effects/chromakey.frag
    56: /usr/share/olive-editor/effects/chromakey.xml
    57: /usr/share/olive-editor/effects/chromaticaberration.frag
    58: /usr/share/olive-editor/effects/chromaticaberration.xml
    59: /usr/share/olive-editor/effects/colorcorrection.frag
    60: /usr/share/olive-editor/effects/colorcorrection.xml
    61: /usr/share/olive-editor/effects/colorsel.frag
    62: /usr/share/olive-editor/effects/colorsel.xml
    63: /usr/share/olive-editor/effects/common.frag
    64: /usr/share/olive-editor/effects/common.vert
    65: /usr/share/olive-editor/effects/crop.frag
    66: /usr/share/olive-editor/effects/crop.xml
    67: /usr/share/olive-editor/effects/crossstitch.frag
    68: /usr/share/olive-editor/effects/crossstitch.xml
    69: /usr/share/olive-editor/effects/directionalblur.frag
    70: /usr/share/olive-editor/effects/directionalblur.xml
    71: /usr/share/olive-editor/effects/dropshadow.xml.disabled
    72: /usr/share/olive-editor/effects/emboss.frag
    73: /usr/share/olive-editor/effects/emboss.xml
    74: /usr/share/olive-editor/effects/findedges.frag
    75: /usr/share/olive-editor/effects/findedges.xml.disabled
    76: /usr/share/olive-editor/effects/fisheye.frag
    77: /usr/share/olive-editor/effects/fisheye.xml
    78: /usr/share/olive-editor/effects/flip.frag
    79: /usr/share/olive-editor/effects/flip.xml
    80: /usr/share/olive-editor/effects/gaussianblur.frag
    81: /usr/share/olive-editor/effects/gaussianblur.xml
    82: /usr/share/olive-editor/effects/huesatbri.frag
    83: /usr/share/olive-editor/effects/huesatbri.xml
    84: /usr/share/olive-editor/effects/invert.frag
    85: /usr/share/olive-editor/effects/invert.xml
    86: /usr/share/olive-editor/effects/lumakey.frag
    87: /usr/share/olive-editor/effects/lumakey.xml
    88: /usr/share/olive-editor/effects/noise.frag
    89: /usr/share/olive-editor/effects/noise.xml
    90: /usr/share/olive-editor/effects/pixelate.frag
    91: /usr/share/olive-editor/effects/pixelate.xml
    92: /usr/share/olive-editor/effects/posterize.frag
    93: /usr/share/olive-editor/effects/posterize.xml
    94: /usr/share/olive-editor/effects/radialblur.frag
    95: /usr/share/olive-editor/effects/radialblur.xml
    96: /usr/share/olive-editor/effects/ripple.frag
    97: /usr/share/olive-editor/effects/ripple.xml
    98: /usr/share/olive-editor/effects/sphere.frag
    99: /usr/share/olive-editor/effects/sphere.xml
   100: /usr/share/olive-editor/effects/swirl.frag
   101: /usr/share/olive-editor/effects/swirl.xml
   102: /usr/share/olive-editor/effects/tile.frag
   103: /usr/share/olive-editor/effects/tile.xml
   104: /usr/share/olive-editor/effects/toonify.frag
   105: /usr/share/olive-editor/effects/toonify.xml
   106: /usr/share/olive-editor/effects/vignette.frag
   107: /usr/share/olive-editor/effects/vignette.xml
   108: /usr/share/olive-editor/effects/volumetriclight.frag
   109: /usr/share/olive-editor/effects/volumetriclight.xml
   110: /usr/share/olive-editor/effects/wave.frag
   111: /usr/share/olive-editor/effects/wave.xml
   113: /usr/share/olive-editor/ts/olive_ar.qm
   114: /usr/share/olive-editor/ts/olive_bs.qm
   115: /usr/share/olive-editor/ts/olive_cs.qm
   116: /usr/share/olive-editor/ts/olive_de.qm
   117: /usr/share/olive-editor/ts/olive_es.qm
   118: /usr/share/olive-editor/ts/olive_fr.qm
   119: /usr/share/olive-editor/ts/olive_id.qm
   120: /usr/share/olive-editor/ts/olive_it.qm
   121: /usr/share/olive-editor/ts/olive_pt-BR.qm
   122: /usr/share/olive-editor/ts/olive_ru.qm
   123: /usr/share/olive-editor/ts/olive_sr.qm
   124: /usr/share/olive-editor/ts/olive_tr.qm
   125: /usr/share/olive-editor/ts/olive_uk.qm
   126: /usr/share/olive-editor/ts/olive_zh-CN.qm
   127: /usr/share/olive-editor/ts/olive_zh-TW.qm

Which is good. But I wanted to do something with those files, so the default formatting wouldn't have worked very well for me. So I tried to format the output to just print the file names, so I added the option --format='%O%~':

yay -Ql olive | awk '{print $2}' | egrep --invert-match '/$' --format='%O%~'

And now the output turned into:

/usr/
/usr/bin/
/usr/share/
/usr/share/applications/
/usr/share/icons/
/usr/share/icons/hicolor/
/usr/share/icons/hicolor/128x128/
/usr/share/icons/hicolor/128x128/apps/
/usr/share/icons/hicolor/128x128/mimetypes/
/usr/share/icons/hicolor/16x16/
/usr/share/icons/hicolor/16x16/apps/
/usr/share/icons/hicolor/16x16/mimetypes/
/usr/share/icons/hicolor/256x256/
/usr/share/icons/hicolor/256x256/apps/
/usr/share/icons/hicolor/256x256/mimetypes/
/usr/share/icons/hicolor/32x32/
/usr/share/icons/hicolor/32x32/apps/
/usr/share/icons/hicolor/32x32/mimetypes/
/usr/share/icons/hicolor/48x48/
/usr/share/icons/hicolor/48x48/apps/
/usr/share/icons/hicolor/48x48/mimetypes/
/usr/share/icons/hicolor/512x512/
/usr/share/icons/hicolor/512x512/apps/
/usr/share/icons/hicolor/512x512/mimetypes/
/usr/share/icons/hicolor/64x64/
/usr/share/icons/hicolor/64x64/apps/
/usr/share/icons/hicolor/64x64/mimetypes/
/usr/share/metainfo/
/usr/share/mime/
/usr/share/mime/packages/
/usr/share/olive-editor/
/usr/share/olive-editor/effects/
/usr/share/olive-editor/ts/

As you can see, it now seems to be ignoring the --invert-match option and is instead matching the regex. Is this a bug or am I just not using the format options correctly?

Thanks for your time.

genivia-inc commented 3 years ago

The --format option does not honor -v and the context options -A, -B, -C, and -y. Perhaps a warning is in order when any of those are used. It makes sense to support at least -v actually.

genivia-inc commented 3 years ago

The man ugrep page states at the end of section FORMAT:

The context options -A, -B, -C, -y, and options -v, --break, --heading,
--color, -T, and --null have no effect on formatted output.

I agree this requires reading the whole section! So I don't expect everyone to know this.

I'll make a change in v3.1 to support -v and update the --format man page to state that context options -A, -B, -C, and -y are ignored.

smac89 commented 3 years ago

Awesome sauce. Thanks for the clarification.

genivia-inc commented 3 years ago

Implemented in v3.1.