首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按结构过滤标签搜索

按结构过滤标签搜索
EN

Unix & Linux用户
提问于 2018-03-21 18:19:53
回答 1查看 74关注 0票数 1

我启用了multiarch,当我运行debtags search时,会得到很多重复的结果。

代码语言:javascript
复制
$ debtags search 'works-with-format::man' | head
docbook-to-man - converter from DocBook SGML into roff man macros
docbook-to-man:i386 - converter from DocBook SGML into roff man macros
docbook-utils - Convert DocBook files to other formats (HTML, RTF, PS, man, PDF)
docbook2x - Converts DocBook/XML documents into man pages and TeXinfo
docbook2x:i386 - Converts DocBook/XML documents into man pages and TeXinfo
doclifter - Convert troff to DocBook
dwww - Read all on-line documentation with a WWW browser
dwww:i386 - Read all on-line documentation with a WWW browser
ebook-speaker - eBook reader that reads aloud in a synthetic voice
ebook-speaker:i386 - eBook reader that reads aloud in a synthetic voice

使用grep有一个解决办法:

代码语言:javascript
复制
$ debtags search 'works-with-format::man' | grep -v ':i386 - ' | head
docbook-to-man - converter from DocBook SGML into roff man macros
docbook-utils - Convert DocBook files to other formats (HTML, RTF, PS, man, PDF)
docbook2x - Converts DocBook/XML documents into man pages and TeXinfo
doclifter - Convert troff to DocBook
dwww - Read all on-line documentation with a WWW browser
ebook-speaker - eBook reader that reads aloud in a synthetic voice
git-man - fast, scalable, distributed revision control system (manual pages)
gman - small man(1) front-end for X
gmanedit - GTK+ man pages editor
gnulib - GNU Portability Library

这假设字符串:i386 -不会出现在任何包描述中,这有点麻烦。有更好的办法吗?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-03-22 21:39:28

代码语言:javascript
复制
debtags search 'works-with-format::man' | awk 'BEGIN { FS="[: ]" }  ! ($1 in seen) { print; seen[$1]=1 }'

这将记住已看到的包(在seen数组的索引中),而不考虑体系结构(因此使用空格和:作为分隔符),如果已经看到,则不再打印它们。因此,它还将显示一个只存在于i386中而不存在于默认(amd64)体系结构中的包(例如:带有hardware::emulation标记的zsnes:i386不存在于zsnes (即zsnes:amd64)中)。因为没有显式架构的包是第一位的(在标签预置算法中.),除非需要,没有必要担心显示额外的:i386

更新:如您所愿,独立脚本文件中相同的awk脚本放在/usr/local/bin/debtagsfilter中,其中包含此内容。

代码语言:javascript
复制
#!/usr/bin/awk -f
BEGIN           {
                        FS="[: ]"
                }
! ($1 in seen)  {
                        print
                        seen[$1]=1
                }

并使可执行文件使用(chmod a+rx /usr/local/bin/filterdebtags),例如:debtags search 'works-with-format::man' | filterdebtags

或者,如果倾向于使用名为/usr/local/bin/debtagswithfilter的“新”版本的标签(因此回到sh作为调用的脚本语言):

代码语言:javascript
复制
#!/bin/sh
debtags "$@" | awk '
BEGIN           {
                        FS="[: ]"
                }
! ($1 in seen)  {
                        print
                        seen[$1]=1
                }
'

比较(我得到了普通的双倍,可能是因为有多个存储源):

代码语言:javascript
复制
$ debtags search 'hardware::emulation'
代码语言:javascript
复制
xtrs - emulator for TRS-80 Model I/III/4/4P computers
xtrs:i386 - emulator for TRS-80 Model I/III/4/4P computers
yabause - beautiful and under-rated Saturn emulator
yabause - beautiful and under-rated Saturn emulator
yabause-gtk - beautiful and under-rated Saturn emulator - Gtk port
yabause-gtk - beautiful and under-rated Saturn emulator - Gtk port
yabause-gtk:i386 - beautiful and under-rated Saturn emulator - Gtk port
yabause-gtk:i386 - beautiful and under-rated Saturn emulator - Gtk port
yabause-qt - beautiful and under-rated Saturn emulator - Qt port
yabause-qt - beautiful and under-rated Saturn emulator - Qt port
yabause-qt:i386 - beautiful and under-rated Saturn emulator - Qt port
yabause-qt:i386 - beautiful and under-rated Saturn emulator - Qt port
zsnes:i386 - Emulator of the Super Nintendo Entertainment System

通过以下方式:

代码语言:javascript
复制
$ debtagswithfilter search 'hardware::emulation'
代码语言:javascript
复制
xtrs - emulator for TRS-80 Model I/III/4/4P computers
yabause - beautiful and under-rated Saturn emulator
yabause-gtk - beautiful and under-rated Saturn emulator - Gtk port
yabause-qt - beautiful and under-rated Saturn emulator - Qt port
zsnes:i386 - Emulator of the Super Nintendo Entertainment System

它也适用于更复杂的搜索请求:

代码语言:javascript
复制
$ debtagswithfilter search 'works-with-format::tex && interface::text-mode'
asymptote - script-based vector graphics language inspired by MetaPost
auctex - integrated document editing environment for TeX etc.
axiom-tex - General purpose computer algebra system: style file for TeX
bibcursed - Interactive program to edit BibTeX bibliographies
chktex - Finds typographic errors in LaTeX
fweb - literate-programming tool for C/C++/Fortran/Ratfor
groff - GNU troff text-formatting system
vim-latexsuite - view, edit and compile LaTeX documents from within Vim
yatex - Yet Another TeX mode for Emacs
票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/432642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档