Regex Sed:正则表达式匹配不带<;的行--
我有一个sed命令来注释掉xml命令Regex Sed:正则表达式匹配不带<;的行--,regex,sed,Regex,Sed,我有一个sed命令来注释掉xml命令 sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml sed的/^\([\t]*\)\(.[0-9a-zA-Z/'web.xml 这似乎奏效了 ^([ \t]*)(?!<!--)([0-9a-zA-Z<].*)$ ^([\t]*)(?!这似乎有效 ^([ \t]*)(?!<!--)([0-9a-zA-Z<].*)$
sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml
sed的/^\([\t]*\)\(.[0-9a-zA-Z/'web.xml
这似乎奏效了
^([ \t]*)(?!<!--)([0-9a-zA-Z<].*)$
^([\t]*)(?!这似乎有效
^([ \t]*)(?!<!--)([0-9a-zA-Z<].*)$
^([\t]*)(?!如果我正确了解您的要求,您可以使用awk:
awk -F"," '!/<!--/&&NF{$0="<!-- Security: "$0"-->"}1' file
awk-F“,”!/“}1”文件
如果我正确了解您的要求,您可以使用awk:
awk -F"," '!/<!--/&&NF{$0="<!-- Security: "$0"-->"}1' file
awk-F“,”!/“}1”文件
以以下方式结束:
startInsert="<!-- Security: "
endInsert=" -->"
whiteSpace="[ \t]*"
char="[0-9a-zA-Z^_)!-/:-@[-\{-~]"
sed "s/^\($whiteSpace\)\(.*$char.*\)$/\1$startInsert\2$endInsert/" $file
sed "s/^\($whiteSpace\)$startInsert\(<!--.*\-->\)$endInsert/\1\2/" $file
startInsert=“”
空格=“[\t]*”
char=“[0-9a-zA-Z^)!-/:-@[-\{-~]”
sed“s/^\($whiteSpace\)\(.*$char.*\)$/\1$startInsert\2$endInsert/”$file
sed“s/^\($whiteSpace\)$startInsert\(\)$endInsert/\1\2/”$file
没有我所希望的那么优雅,但却很有魅力。结果是:
startInsert="<!-- Security: "
endInsert=" -->"
whiteSpace="[ \t]*"
char="[0-9a-zA-Z^_)!-/:-@[-\{-~]"
sed "s/^\($whiteSpace\)\(.*$char.*\)$/\1$startInsert\2$endInsert/" $file
sed "s/^\($whiteSpace\)$startInsert\(<!--.*\-->\)$endInsert/\1\2/" $file
startInsert=“”
空格=“[\t]*”
char=“[0-9a-zA-Z^)!-/:-@[-\{-~]”
sed“s/^\($whiteSpace\)\(.*$char.*\)$/\1$startInsert\2$endInsert/”$file
sed“s/^\($whiteSpace\)$startInsert\(\)$endInsert/\1\2/”$file
虽然没有我希望的那么优雅,但却很有魅力。是的,我尝试过(以及不同的变体),但我无法让它工作。它最终没有突出显示任何内容。进一步阅读后,sed似乎不支持这些表达式。您必须使用sed和活动perl模式(-R)。在这里找到信息:Coool。这也是我的想法。+1用于澄清。是的,我已经尝试过了(和不同的变体),但无法使其工作。它最终没有突出显示任何内容。进一步阅读后,sed似乎不支持这些表达式。您必须使用sed和活动perl模式(-R).在这里找到信息:Coool。我也是这么想的。+1表示澄清。hmmm,我更愿意使用sed,但+1表示建议。hmmm,我更愿意使用sed,但+1表示建议。
startInsert="<!-- Security: "
endInsert=" -->"
whiteSpace="[ \t]*"
char="[0-9a-zA-Z^_)!-/:-@[-\{-~]"
sed "s/^\($whiteSpace\)\(.*$char.*\)$/\1$startInsert\2$endInsert/" $file
sed "s/^\($whiteSpace\)$startInsert\(<!--.*\-->\)$endInsert/\1\2/" $file