I have a file which looks like this :
我有一个看起来像这样的文件:
9 3 16 2
10 17
11 R-C R-C R-C R-C
I would like to replace each digit 'number' with 'number + 1'
我想用'number + 1'替换每个数字'number'
Say for example, 9 -> 10, 2 -> 3, 17 -> 18 and so on.
比方说,9 - > 10,2 - > 3,17 - > 18,依此类推。
I know that you can use \1 to remember the pattern in sed. But not sure how to add 1 to it.
我知道你可以使用\ 1来记住sed中的模式。但不知道如何添加1。
1 个解决方案
#1
2
Try this awk
command:
试试这个awk命令:
awk '{for(i=1;i<=NF;i++){if(match($i,/^[0-9]+$/)){$i+=1}}print}' input.txt
The result is:
结果是:
10 4 17 3
11 18
12 R-C R-C R-C R-C
If you need to keep those white spaces, run this command in vim
:
如果需要保留这些空格,请在vim中运行以下命令:
:%s/[0-9]\+/\=submatch(0)+1/g
The result is:
结果是:
10 4 17 3
11 18
12 R-C R-C R-C R-C
#1
2
Try this awk
command:
试试这个awk命令:
awk '{for(i=1;i<=NF;i++){if(match($i,/^[0-9]+$/)){$i+=1}}print}' input.txt
The result is:
结果是:
10 4 17 3
11 18
12 R-C R-C R-C R-C
If you need to keep those white spaces, run this command in vim
:
如果需要保留这些空格,请在vim中运行以下命令:
:%s/[0-9]\+/\=submatch(0)+1/g
The result is:
结果是:
10 4 17 3
11 18
12 R-C R-C R-C R-C