【问题标题】:Find a word and increment the number in the word & save into new files查找一个单词并增加单词中的数字并保存到新文件中
【发布时间】:2016-07-08 15:57:07
【问题描述】:

我正在寻找一个 perl/awk/sed 命令来自动增加文件 P1.tcl 中的数字行:

run_build_model sparc_ifu_dec
run_drc
set_faults -model path_delay -atpg_effectiveness -fault_coverage
add_delay_paths P1
set_atpg -abort_limit 1000
run_atpg -ndetects 1000

我想将 P1 从 P2 更改为 P500 并保存到新文件中,例如 P2.tcl,P3.tcl.... P500.tcl

我在网上搜索了这个,但找到了替换/生成一个文件的唯一方法。比如P2.tcl

最好的,

在英

【问题讨论】:

  • 使用 var 和循环

标签: awk sed numbers increment


【解决方案1】:

未经测试:

for i in {2..500}; do
    cp P1.tcl P$i.tcl
    sed -i s/P1/P$i/ P$i.tcl
done

【讨论】:

  • 请注意,Bash 3+ 和 ksh 支持范围大括号扩展,而不是所有 shell。
【解决方案2】:

awk 对于这么长的循环来说不太清楚,但速度更快:

awk '{for (n=2; n<=500; n++) {line = gensub(/P1/, "P" n, "g", $0); print line > "P" n ".tcl"}}' P1.tcl

使用gensubP1 替换为"P" n

【讨论】:

    猜你喜欢
    • 2016-08-19
    • 1970-01-01
    • 2017-07-01
    • 2012-10-31
    • 2022-08-03
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多