[问题] grep 撷取任意字符的问题

楼主: chiaohuang (chiao)   2018-09-07 23:20:49
不好意思
这问题 我找很久了 还是找不到
问题是这样
假如我有一个文字档
例如:
I wanna leave my footprints on the sands of time Know
there was something that, and something that I left behind
When I leave this world, I'll leave no regrets Leave something to remember,
我想找这行出来
there was something that, and something that I left behind
我下的方式是
cat txt | grep -o "there * that"
这边* 我想要说可以是任意字串
但grep 任意字符 似乎不是用*
我google很久 有找到一个 \w*
可以表示任意一个字符
但这不符合我的需求
因为我不知道中间的任意字元会有几个
请问有人有好方法吗??
谢谢
作者: rickieyang (Rickie Yang)   2018-09-07 23:32:00
* 代表跟前一个字符一样, 0~N 个cat txt |grep "there .* that"然后加 -o 只会从 there 显示到 that (only-matching)可以参考一下 regular expression
作者: gholk (正常正高)   2018-09-08 01:52:00
regexp 正则表示式和 glob 万用字符是二种不同的东西,grep 只支援 regexp 。
作者: axuiolji (泰)   2018-09-11 16:33:00
参考 “正规表示法”

Links booklink

Contact Us: admin [ a t ] ucptt.com