sed:在一个sed通话中匹配,删除和替换

琉璃苣

假设我有一个类似的字符串:

Image.Resolution=1024x768,800x600,640x480,480x360,320x240,240x180,160x120,1280x720

我想使用sed删除第一部分(Image.Resolution=),然后用逗号分隔其余部分,以便将所有分辨率放入bash数组中。

我知道如何分两步(两个sed调用)来执行此操作,例如:

sed 's/Image.Resolution=//g' | sed 's/,/ /g'

但是作为一种练习,我想知道是否有一种方法可以一次完成。

先感谢您。

列夫·列维茨基

放在;命令之间:

sed 's/Image.Resolution=//g; s/,/ /g'

来自info sed

3 `sed' Programs
****************

A `sed' program consists of one or more `sed' commands, passed in by
one or more of the `-e', `-f', `--expression', and `--file' options, or
the first non-option argument if zero of these options are used.  This
document will refer to "the" `sed' script; this is understood to mean
the in-order catenation of all of the SCRIPTs and SCRIPT-FILEs passed
in.

   Commands within a SCRIPT or SCRIPT-FILE can be separated by
semicolons (`;') or newlines (ASCII 10).  Some commands, due to their
syntax, cannot be followed by semicolons working as command separators
and thus should be terminated with newlines or be placed at the end of
a SCRIPT or SCRIPT-FILE.  Commands can also be preceded with optional
non-significant whitespace characters.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用“ sed”仅替换第一个和最后一个匹配项

sed仅替换行中的第一个和最后一个空格

如何只用sed替换一行中的最后一个匹配项?

如何使用sed仅替换文件中的第一个匹配项?

sed:替换匹配行中的一个或多个组值

循环使用sed。用一个文件中的文本替换另一个文件中的匹配模式

仅删除sed的第一个匹配项

sed仅删除第一个模式匹配

sed-执行替换后,从列出的值中删除最后一个逗号

awk / sed / grep删除与另一个文件中的字段匹配的行

在 sed 中的第一个匹配后删除 n 行

如何使用 Sed 和 Awk 在 XML 中替换另一个属性

替换特定行sed中的最后一个单词

在一个 sed 中匹配负模式和正模式

如何使用 sed 命令从匹配的字符串中删除行直到下一个匹配

sed / awk:删除所有与一个单词匹配的行,而不跟一个单词

用 sed 匹配后替换第一个匹配

sed 多个匹配替换第一个匹配值

使用sed替换文件中的第一个匹配项-为什么要打印后续行?

如果在sed命令中仅行的第一个字符匹配,则替换值

sed +从路径中删除第一个目录

使用sed,如何删除与一组模式中的任何一个匹配的所有初始行?

sed:仅用该行中第一个出现的字符串替换单词,直到最后一个匹配为止

sed 替换包含 '/' 和空格的整行匹配字符串,用另一个字符串替换它

使用sed替换为第一个匹配字符

sed - 在第一个正则表达式匹配后替换逗号

将 sed 传递给数组以替换第一个匹配项不起作用

仅在第一个匹配行上用sed替换

sed-尝试替换比赛后的第一个匹配项