首页 > 解决方案 > Linux用连续数字替换特定字符串

问题描述

CONFIG.CONFIG
create state file${number_of_edges} {
 {interval=60 
idle_interval_notification="DISABLED"}    
}
create state file${number_of_edges} {
 {interval=60 
idle_interval_notification="DISABLED"}    
}

我有文件,其内容如上。我想用 0,1,2 等连续数字替换 ${number_of_edges} 字符串

EXPECTED OUTPUT
create state file0 {
 {interval=60 
idle_interval_notification="DISABLED"}    
}
create state file1{
 {interval=60 
idle_interval_notification="DISABLED"}    
}
create state file2 {
 {interval=60 
idle_interval_notification="DISABLED"}    
}

标签: regexlinuxbashawksed

解决方案


我得到了解决方案。

命令-

awk -vRS=edge '{$0=n$0;ORS=RT}++n' FILE

推荐阅读