[求助]一个有关awk的应用
时间:2011-06-28
来源:互联网
我现在有一个文件,内容如下:
2011-02-08 weru 239874 2394
2011-02-09 35 234 eoir
2011-02-10 soiwo 235433 2fu9
2011-02-08 joi jfw cowq
需要按第一域把记录分到相应的单独的文本文件中去。
比如第一域时间如果等于2011-02-08,则把相应记录放到名为2011-02-08的文件中去。求代码~~~!
2011-02-08 weru 239874 2394
2011-02-09 35 234 eoir
2011-02-10 soiwo 235433 2fu9
2011-02-08 joi jfw cowq
需要按第一域把记录分到相应的单独的文本文件中去。
比如第一域时间如果等于2011-02-08,则把相应记录放到名为2011-02-08的文件中去。求代码~~~!
作者: 紫OS琨 发布时间: 2011-06-28
回复 紫OS琨
复制代码
- awk '{print >$1".txt"}' urfile
作者: yinyuemi 发布时间: 2011-06-28
yinyuemi 发表于 2011-06-28 22:22
这个第四行为什么没有把第一行的覆盖掉?
这个第四行为什么没有把第一行的覆盖掉?
作者: 251995427 发布时间: 2011-06-28
回复 251995427
QUOTE:
print items > output-file
This type of redirection prints the items onto the output file output-file. The file name output-file can be any expression. Its value is changed to a string and then used as a file name (see section Actions: Expressions).
When this type of redirection is used, the output-file is erased before the first output is written to it. Subsequent writes do not erase output-file, but append to it. If output-file does not exist, then it is created.
For example, here is how one awk program can write a list of BBS names to a file `name-list' and a list of phone numbers to a file `phone-list'. Each output file contains one name or number per line.
awk '{ print $2 > "phone-list"
print $1 > "name-list" }' BBS-list
print items >> output-file
This type of redirection prints the items onto the output file output-file. The difference between this and the single-`>' redirection is that the old contents (if any) of output-file are not erased. Instead, the awk output is appended to the file.
This type of redirection prints the items onto the output file output-file. The file name output-file can be any expression. Its value is changed to a string and then used as a file name (see section Actions: Expressions).
When this type of redirection is used, the output-file is erased before the first output is written to it. Subsequent writes do not erase output-file, but append to it. If output-file does not exist, then it is created.
For example, here is how one awk program can write a list of BBS names to a file `name-list' and a list of phone numbers to a file `phone-list'. Each output file contains one name or number per line.
awk '{ print $2 > "phone-list"
print $1 > "name-list" }' BBS-list
print items >> output-file
This type of redirection prints the items onto the output file output-file. The difference between this and the single-`>' redirection is that the old contents (if any) of output-file are not erased. Instead, the awk output is appended to the file.
作者: yinyuemi 发布时间: 2011-06-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28