Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用sed在字符串中附加带值的字符串_Regex_Linux_String_Sed_Awk - Fatal编程技术网

Regex 使用sed在字符串中附加带值的字符串

Regex 使用sed在字符串中附加带值的字符串,regex,linux,string,sed,awk,Regex,Linux,String,Sed,Awk,我有以以下结尾的字符串: ...", "VERI-1000") 我正在尝试使用sed(或任何其他工具)将它们格式化为 ...", "(VERI-1000)" uid="1000"/> “VERI”和“1000”值会多次更改,因此它不总是“VERI”,也不总是“1000” 我假设我正在尝试搜索“)字符串前面的数值,然后在uid=“WithGNU sed之后插入该值。您可以执行以下操作: sed -r 's_([[:digit:]]+)"\)$_& uid="\1"/>_'

我有以以下结尾的字符串:

...", "VERI-1000")
我正在尝试使用sed(或任何其他工具)将它们格式化为

...", "(VERI-1000)" uid="1000"/>
“VERI”和“1000”值会多次更改,因此它不总是“VERI”,也不总是“1000”


我假设我正在尝试搜索“)字符串前面的数值,然后在uid=“

With
GNU sed
之后插入该值。您可以执行以下操作:

sed -r 's_([[:digit:]]+)"\)$_& uid="\1"/>_'
该命令将替换以下内容:

([[:digit:]+)“\)$
^起始编号组(编号1)
^^^^^^^^^^^^任意位数
^闭号群
^^^^报价、括号、下线
为此:

&uid=“\1”/>
^所有匹配的字符串
^^第1组的内容
例如:

sed -r 's_([[:digit:]]+)"\)$_& uid="\1"/>_' <<<'...", "VERI-1000")'
...", "VERI-1000") uid="1000"/>
试试这个:

sed -i.bak 's~"\([^"-]*\)-\([0-9]*\)")~"(\1-\2") uid="\2"/>~' file
sed -i.bak 's~"\([^"-]*\)-\([0-9]*\)")~"(\1-\2") uid="\2"/>~' file