免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2162 | 回复: 8
打印 上一主题 下一主题

[文本处理] 请教下 find 带空格,输出带颜色的细节 [复制链接]

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:51:33
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-12-26 09:47 |只看该作者 |倒序浏览
我想用find 找文件,然后输出时让我所输入的字串带颜色

注意 "\(DD\)\ .xls" 点的前面有个空格
$ ls
票(DD) .xls

1.是可以找到的,但是没有颜色
f 是一个shell 内容是sudo find -iname "*${1}*"
$ f "\(DD\)\ .xls"
./票(DD) .xls

2.这个是找不到的
f 是一个shell 内容是sudo find -iname "*${1}*" | grep -i "${1}" --color=auto
$ f "\(DD\)\ .xls"

我想用find 输出带颜色,还有什么好办法吗?

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [报告]
发表于 2014-12-26 10:27 |只看该作者
回复 1# qimuzhi

$ ls
票(DD) .xls

which one do you like?

1. grep
$ ls | grep .
票(DD) .xls

2. xargs and echo with ANSI color
$ ls | xargs -i echo -e "\e[31m{}\e[0m"
票(DD) .xls

3. xargs and echo with ANSI color
$ ls | xargs -i echo -e "\e[41m{}\e[0m"
票(DD) .xls

$ find . | xargs -i echo -e "\e[41m{}\e[0m"
.
./票(DD) .xls



   

论坛徽章:
0
3 [报告]
发表于 2014-12-26 10:40 |只看该作者
回复 1# qimuzhi

我这里可以啊
   

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:51:33
4 [报告]
发表于 2014-12-26 10:43 |只看该作者
回复 2# jason680

Thanks for your reply!

I want to use ''find '' command to search file .
And it shows to me what I have inputted with color.

The search result shows like this:
./票(DD) .xls





论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:51:33
5 [报告]
发表于 2014-12-26 10:45 |只看该作者
回复 3# Looiml

你搜索的文件,没有空格和特殊符号。我们的文件名字有时候,会参杂着很奇特的东西。

   

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
6 [报告]
发表于 2014-12-26 11:27 |只看该作者
本帖最后由 jason680 于 2014-12-26 11:27 编辑

回复 4# qimuzhi

$ ./f '(DD) .xls'
./票(DD) .xls

$ cat f
do find -iname "*${1}*" | grep -iP "\Q${1}\E" --color=auto

   

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:51:33
7 [报告]
发表于 2014-12-26 13:02 |只看该作者
回复 6# jason680

Thanks for your help !!!

I want to learn this knowledge.
How can I get the document of ""\Q${1}\E"".
What does the \Q mean?
What does the \E mean?

Thanks a lot.




   

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:51:33
8 [报告]
发表于 2014-12-26 13:21 |只看该作者
回复 7# qimuzhi

Thanks

I have found it about "\Q \E"

AFS:
\Q is the string interpolation alias for quotemeta.  It escapes all non-word characters after it in an double quoted string AFTER the interpolation step.  Therefore ensuring that the value of $line is treated as a literal string.

\E indicates that \Q should stop.  Technically it's not needed in your regex since it's at the end anyway.  But for consistency I always include it, since it's a way of explicitly documenting that you truly mean to escape just the value of $line.

You can read more about interpolation of double quoted strings here:
perldoc perlop - Quote and Quote-like Operators
perldoc perlop - Gory details of parsing quoted constructs.
”www。tek-tips。com/viewthread.cfm?qid=1426346“

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:51:33
9 [报告]
发表于 2014-12-26 13:22 |只看该作者
回复 6# jason680


Thanks

I have found it about "\Q \E"

AFS:
\Q is the string interpolation alias for quotemeta.  It escapes all non-word characters after it in an double quoted string AFTER the interpolation step.  Therefore ensuring that the value of $line is treated as a literal string.

\E indicates that \Q should stop.  Technically it's not needed in your regex since it's at the end anyway.  But for consistency I always include it, since it's a way of explicitly documenting that you truly mean to escape just the value of $line.

You can read more about interpolation of double quoted strings here:
perldoc perlop - Quote and Quote-like Operators
perldoc perlop - Gory details of parsing quoted constructs.
”www。tek-tips。com/viewthread.cfm?qid=1426346“




   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP