avatar
c*e
1
用 awk 是不是只能读文件内容,而不能修改文件内容?
我用awk来实现把 backuptimes 加 1 的功能.我是这样写的:
awk '/backuptimes/{$2+=1;print}' logfile
print的结果是加 1 后的,但是文件的内容并没有改变,也就是没有加 1 .
难道awk不能改文件?
avatar
h*a
2
ft, redirection >

【在 c********e 的大作中提到】
: 用 awk 是不是只能读文件内容,而不能修改文件内容?
: 我用awk来实现把 backuptimes 加 1 的功能.我是这样写的:
: awk '/backuptimes/{$2+=1;print}' logfile
: print的结果是加 1 后的,但是文件的内容并没有改变,也就是没有加 1 .
: 难道awk不能改文件?

avatar
c*e
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 >
avatar
m*u
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。