添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

输出应该是这样的

<TotalSum>300.89</TotalSum><Info><Value>A1234567 100 14 B1234567 200 75</Value></Info>

我试图执行的脚本如下,因为我只需要删除<Value>字段中的特殊字符。

$search_text=`grep -i Value filename`
for i in $search_text
    sed -e 's/\.//g'
    
5 个评论
你尝试过什么?
I used below command but it is failing sed 's/\<Value>\.//g' file.txt
始终将你所尝试的代码放在问题中,而不是在评论中。这样做的目的是为了显示一些努力 :)
谢谢你的意见,PesaThe。你给我的命令是在文件中全部替换的。我已经用我的尝试重新表述了我的问题。
提到这些值应该只在<Value>中改变,这是一个非常关键的信息:)更新了我的解决方案。
xml
linux
bash
sed
Prasad
Prasad
发布于 2018-01-04
1 个回答
PesaThe
PesaThe
发布于 2018-01-04
已采纳
0 人赞同

Using GNU sed with extended regex:

sed -r '
    s#(<Value>.*[[:digit:]])\.(.*</Value>)#\1 \2# 
    s#(<Value>.*[[:alpha:]])\.(.*</Value>)#\1\2#
' file

或作为一个单行本。

sed -r ':del; s#(<Value>.*[[:digit:]])\.(.*</Value>)#\1 \2#; s#(<Value>.*[[:alpha:]])\.(.*</Value>)#\1\2#; t del' file
  • -r for extended regex. It's just for convenience, otherwise you would have to use \( ... \)
  • s#text#replacement# you can choose a different delimiter also just for convenience. Then there is no need to escape literal /
  • :del is a definiton of a label
  • ( ) save the matches that can be later back-referenced using \1, \2, ...
  • tdel jumps to label :del if the s commands changed the line. This is to ensure all of the dots get replaced
  •