我想分裂“庸俗”:"CVE-2018-17435 (Hdf5)分裂在这里“的第二个空间。我如何使用sed来完成这个任务?
我的意见:
"vulnid": "CVE-2018-17435 (hdf5)splitmehere"
"stuff":"stuffhere(somedata)"
"vulnid": "CVE-2018-17435 (hdf5)splitmehere"
"stuff":"stuffhere"
"vulnid": "CVE-2018-17435 (hdf5)splitmehere"
"stuff":"stuffhere"预期产出:
"vulnid": "CVE-2018-17435"
"product:" (hdf5)splitmehere"
"stuff":"stuffhere(somedata)"
"vulnid": "CVE-2018-17435"
"product:" (hdf5)splitmehere"
"stuff":"stuffhere"
"vulnid": "CVE-2018-17435"
"product:" (hdf5)splitmehere"
"stuff":"stuffhere"我尝试使用这个表达式的一个变体:
sed -r 's/(*.*) (*.*) (*.*)/\1 \2 \3/'发布于 2018-11-13 11:43:04
一个可能的解决办法是:
$ sed 's/\("vulnid":\) \(.*\) \(.*\)"/\1 \2"\n"product": "\3"/' file
"vulnid": "CVE-2018-17435"
"product": "(hdf5)splitmehere"
"stuff":"stuffhere(somedata)"
"vulnid": "CVE-2018-17435"
"product": "(hdf5)splitmehere"
"stuff":"stuffhere"
"vulnid": "CVE-2018-17435"
"product": "(hdf5)splitmehere"
"stuff":"stuffhere" 发布于 2018-11-13 11:51:35
你自己的建议
sed -e "s/ /\n/2"几乎和你描述的一样。剩下的就是将额外的"product:"文本放在行符周围:
sed -e 's/ /"\n"product:" /2'(为了在表达式中使用双引号,我将外部引号改为单引号。)
有些版本的sed可能不会将\n解释为换行符。sed规格说明指出:
可以通过将替换到行中来拆分行。应用程序应在替换的之前以一个转义它。
即。
sed -e 's/ /"\
"product:" /2'https://unix.stackexchange.com/questions/481430
复制相似问题