我的情况是这样的 - 我有一个文件:我使用正则表达式有什么问题?
this line(5)
that line(6)
another line(9)
one more(88)
last line(156)
我需要在括号将值更改为:
this line(1)
that line(2)
another line(3)
one more(4)
last line(5)
基本上,使值从1
下令开始现在,这里是我的代码:
#!/bin/bash
FILE=$1
COUNT=0
echo "Working with $FILE"
if [ -f $FILE ]; then
while read -r line; do
echo ${line/\([0-9]{1,3}\)/\($COUNT\)};
let COUNT++;
done < $FILE
else
echo "File does not exist!"
fi
这是我得到:
this line(5))/(0)}
that line(6))/(1)}
another line(9))/(2)}
one more(88))/(3)}
last line(156))/(4)}
我在做什么错?我怎样才能在正则表达式中指定多个任意长度?
非常感谢。
感谢您的帮助,我结束了使用最为相似的德雷克的编辑响应的解决方案,尽管谢谢大家的帮助! –