c********e 发帖数: 417 | 1 用 awk 是不是只能读文件内容,而不能修改文件内容?
我用awk来实现把 backuptimes 加 1 的功能.我是这样写的:
awk '/backuptimes/{$2+=1;print}' logfile
print的结果是加 1 后的,但是文件的内容并没有改变,也就是没有加 1 .
难道awk不能改文件? | h******a 发帖数: 198 | 2 ft, redirection >
【在 c********e 的大作中提到】 : 用 awk 是不是只能读文件内容,而不能修改文件内容? : 我用awk来实现把 backuptimes 加 1 的功能.我是这样写的: : awk '/backuptimes/{$2+=1;print}' logfile : print的结果是加 1 后的,但是文件的内容并没有改变,也就是没有加 1 . : 难道awk不能改文件?
| c********e 发帖数: 417 | 3 I'm not sure if redirection would work.
The logfile already exists, the > will not proceed. I can redirect to
a new file, remove the logfile, and rename the new file to logfile. But
I think it's not a good idea.
What's more,there are lots of other information in the logfile. I only
change the backuptimes. There is no need to redirect the whole file.
Thanks anyway.
【在 h******a 的大作中提到】 : ft, redirection >
| m**u 发帖数: 5 | 4 use sed then.
【在 c********e 的大作中提到】 : I'm not sure if redirection would work. : The logfile already exists, the > will not proceed. I can redirect to : a new file, remove the logfile, and rename the new file to logfile. But : I think it's not a good idea. : What's more,there are lots of other information in the logfile. I only : change the backuptimes. There is no need to redirect the whole file. : Thanks anyway.
|
|