批处理之家's Archiver

netdzb 发表于 2019-7-16 21:05

这个sed的匹配表达是怎么写

匹配root开始,中间任意,shengli结束的字符串

原文本是这样的,

rootabcdfershenglilkjklll
rootabcdfershengli
rootabc-6hgdfershengli

希望得到下面的结果
rootabcdfershengli
rootabc-6hgdfershengli

netdzb 发表于 2019-7-16 21:38

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221920&ptid=53357]1#[/url] [i]netdzb[/i] [/b]

sed -n "/root.*shengli$/p" ceshi.txt

我自己写出来了。

原来是这样写的,难怪通不过。
sed -n "/root.*$shengli/p" ceshi.txt

Batcher 发表于 2019-7-16 22:26

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=221921&ptid=53357]2#[/url] [i]netdzb[/i] [/b]


你写的不对,应该是这样:
sed -n "/[color=Red]^[/color]root.*shengli$/p" ceshi.txt

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.