如何使用SED删除字符串和空格之间的文本

如何使用SED删除字符串和空格之间的文本,sed,Sed,我有一个文件,里面有重复的行,就像这样 <stack-block name="B" sub-type="SBL" type="ABM_BLOCK" level="2" parent-name="PBTYRD" geo-anchor-latitude="-34.96723069348281" geo-anchor-longitude="150.2157080161554" geo-anchor-orientation="72.35290364141252" z-index-min="1" /

我有一个文件,里面有重复的行,就像这样

<stack-block name="B" sub-type="SBL" type="ABM_BLOCK" level="2" parent-name="PBTYRD" geo-anchor-latitude="-34.96723069348281" geo-anchor-longitude="150.2157080161554" geo-anchor-orientation="72.35290364141252" z-index-min="1" />
<stack-block name="C" sub-type="SBL" type="ABM_BLOCK" level="2" parent-name="PBTYRD" geo-anchor-latitude="-34.967529872288864" geo-anchor-longitude="150.2145108805486" geo-anchor-orientation="72.35290364141252" z-index-min="1" />

……等等

我想从包含地理定位纬度短语的文件行中删除地理定位纬度=“-34.96723069348281”部分,直到第二个双引号

我尝试了sed-I的/geo-anchor-latitude.*/'文件名,但没有成功,因为它从geo-anchor-latitude到行尾的所有内容都被删除了


有什么线索吗?谢谢。

您可以在sed中使用扩展正则表达式(-E)来完成这项工作

sed -Ei 's/geo-anchor-latitude="[-0-9]+[.][0-9]+"//' filename

此正则表达式查找latitude属性,后跟任意位数的十进制数。

您可以将扩展正则表达式(-E)与sed一起使用

sed -Ei 's/geo-anchor-latitude="[-0-9]+[.][0-9]+"//' filename

此正则表达式查找latitude属性,后跟任意位数的十进制数。

是否尝试以下操作:

sed -i 's/geo-anchor-latitude="[^"]*"//' filename
输出:

<stack-block name="B" sub-type="SBL" type="ABM_BLOCK" level="2" parent-name="PBTYRD"  geo-anchor-longitude="150.2157080161554" geo-anchor-orientation="72.35290364141252" z-index-min="1" />
<stack-block name="C" sub-type="SBL" type="ABM_BLOCK" level="2" parent-name="PBTYRD"  geo-anchor-longitude="150.2145108805486" geo-anchor-orientation="72.35290364141252" z-index-min="1" />

regex
geo-anchor-latitude=“[^”]*”
匹配子字符串,例如:

  • 文字字符串
    geo-anchor-latitude=“
  • 后跟除
  • 后跟双引号

然后使用
s
命令删除上面匹配的子字符串。

是否尝试以下操作:

sed -i 's/geo-anchor-latitude="[^"]*"//' filename
输出:

<stack-block name="B" sub-type="SBL" type="ABM_BLOCK" level="2" parent-name="PBTYRD"  geo-anchor-longitude="150.2157080161554" geo-anchor-orientation="72.35290364141252" z-index-min="1" />
<stack-block name="C" sub-type="SBL" type="ABM_BLOCK" level="2" parent-name="PBTYRD"  geo-anchor-longitude="150.2145108805486" geo-anchor-orientation="72.35290364141252" z-index-min="1" />

regex
geo-anchor-latitude=“[^”]*”
匹配子字符串,例如:

  • 文字字符串
    geo-anchor-latitude=“
  • 后跟除
  • 后跟双引号

然后通过
s
命令删除上面匹配的子字符串。

编辑:每行的纬度值都会更改,因此我无法在任何命令中使用这些数字。编辑:每行的纬度值都会更改,因此我无法在任何命令中使用这些数字。