简体   繁体   English

如何获取grep文件路径结果的插件名称?

[英]How can i get the plugin name of a grep filepath result?

I have used grep -rsl "tinymce.plugins" . | sort 我已经使用了grep -rsl "tinymce.plugins" . | sort grep -rsl "tinymce.plugins" . | sort grep -rsl "tinymce.plugins" . | sort to get a longer list of files including references to tinyMCE plugins. grep -rsl "tinymce.plugins" . | sort以获得更长的文件列表,包括对tinyMCE插件的引用。 Here is a short excerpt of what the results list looks like: 以下是结果列表的简短摘录:

./assets/javascripts/old/tiny_mce/plugins/preview/editor_plugin.js
./assets/javascripts/old/tiny_mce/plugins/preview/editor_plugin_src.js
./assets/javascripts/old/tiny_mce/plugins/print/editor_plugin.js
./assets/javascripts/old/tiny_mce/plugins/print/editor_plugin_src.js

I now want to find a way to make a list with all the plugin names and put it into a file. 我现在想找到一种方法来列出所有插件名称,并将其放入文件中。

Example: 例:

results.txt: RESULTS.TXT:

preview 预习
print 打印

How can i achieve this? 我怎样才能做到这一点? Thank you and sorry if my english is clunky. 谢谢,抱歉,如果我的英语不好。

You could try the below grep command, 您可以尝试以下grep命令,

$ command | grep -oP '[^\/]*(?=\/[^\/]*$)' | sort -u
preview
print

this awk one-liner gives you the result in one shot: 这个awk单线可以在一枪中为您提供结果:

whatever|awk -F'plugins/' '{sub("/.*","",$2);$0=$2}!a[$0]++'

with your four lines, it outputs: 用您的四行代码,它输出:

preview
print

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM