Batch file 在batchfile中使用sed获取其他两个字符串之间的字符串
我有一个包含以下html代码的文件:Batch file 在batchfile中使用sed获取其他两个字符串之间的字符串,batch-file,sed,Batch File,Sed,我有一个包含以下html代码的文件: <p class="center-block"><img alt="ourpicture" class="picture" src="http://mypage.com/ourpicture123" /></p> 现在我想得到像这样的来源。 如何使用sed处理此问题?如果我可以通过sed查找'src=“'before and'”after.,那就太好了 $ sed -n 's/.*\bsrc="\([^"]*\)"
<p class="center-block"><img alt="ourpicture" class="picture" src="http://mypage.com/ourpicture123" /></p>
现在我想得到像这样的来源。
如何使用sed处理此问题?如果我可以通过sed查找'src=“'before and'”after.,那就太好了
$ sed -n 's/.*\bsrc="\([^"]*\)".*/\1/p' file
http://mypage.com/ourpicture123
通过grep
grep -oP '\bsrc="\K[^"]*(?=")' file
如果一行中包含多个
src
属性,则上述sed命令将不起作用<上述grep命令中的code>\K将在最终打印时放弃先前匹配的src=“
字符。以下是awk
版本:
awk -F'src="' '{split($2,a,"\"");print a[1]}' file
http://mypage.com/ourpicture123
或者像这样:
awk -F'src="' '{sub(/".*$/,"",$2);print $2}' file
http://mypage.com/ourpicture123
如果您有几行,并且只需要带有
src=
do的行:
awk -F'src="' 'NF>1{split($2,a,"\"");print a[1]}' file
http://mypage.com/ourpicture123
谢谢你的快速回答。当我使用你的命令时,我得到了一个错误。现在确定我是否翻译正确,但是类似这样的内容:…未知命令:'''''sed:-e Ausdruck#1,Zeichen 1:unbekanner Befehl:''''