我正在尝试编写脚本以自动化生成具有不同参数的多个输出文件的过程。这需要在以下代码语句中的CONFIG.c_mm2s_burst_size和CONFIG.c_s2mm_burst_size之后替换花括号中的数字。
set_property -dict [ list CONFIG.c_include_mm2s {1} CONFIG.c_include_mm2s_dre {0} CONFIG.c_include_s2mm_dre {0} CONFIG.c_include_sg {0} CONFIG.c_m_axi_mm2s_data_width {32} CONFIG.c_m_axis_mm2s_tdata_width {32} CONFIG.c_micro_dma {0} CONFIG.c_mm2s_burst_size {2} CONFIG.c_s2mm_burst_size {2} CONFIG.c_sg_length_width {23} ] $axi_dma_0
该代码在tcl中。我尝试了变量替换,但对于诸如此类的内容无法正确解释CONFIG.c_mm2s_burst_size {$var}
因此,我认为使用sed和perl替换文本中的数字应该并不困难。但是,我搜索并尝试了一整夜都没有成功。
我试过了:
sed -r 's/burst_size\>\s\{(\d+)\}/256/g'
sed -r 's/burst_size\s\{(\.+)\}/256/g'
sed -r 's/burst_size#\{(\d+)\}/256/g'
sed -r 's/burst_size\s\\{(\d+)\\}/256/g'
还有很多,它们都不起作用。我正在将Ubuntu与GNU 4.2.2一起使用。只要我系统地更改号码,就欢迎使用其他语言的其他班轮。
非常感谢
要替换{}
括号中的字符串前面的数字burst_size
,您可以使用下面的sed命令。sed不支持\s
或\d
。相反的\s
,你可以使用POSIX符号[[:space:]]
和代替\d
,你可以使用[0-9]
sed 's/\(burst_size \+{\)[0-9]\+}/\1256}/g'
sed -r 's/(burst_size +\{)[0-9]+\}/\1256}/g'
例子:
$ echo 'CONFIG.c_mm2s_burst_size {2} CONFIG.c_s2mm_burst_size {2} CONFIG.c_sg_length_width {23} ] $axi_dma_0' | sed 's/\(burst_size \+{\)[0-9]\+}/\1256}/g'
CONFIG.c_mm2s_burst_size {256} CONFIG.c_s2mm_burst_size {256} CONFIG.c_sg_length_width {23} ] $axi_dma_0
$ echo 'CONFIG.c_mm2s_burst_size {2} CONFIG.c_s2mm_burst_size {2} CONFIG.c_sg_length_width {23} ] $axi_dma_0' | sed -r 's/(burst_size +\{)[0-9]+\}/\1256}/g'
CONFIG.c_mm2s_burst_size {256} CONFIG.c_s2mm_burst_size {256} CONFIG.c_sg_length_width {23} ] $axi_dma_0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句