+ -
当前位置:首页 → 问答吧 → [求助]一个有关awk的应用

[求助]一个有关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的文件中去。求代码~~~!

作者: 紫OS琨   发布时间: 2011-06-28

回复 紫OS琨
  1. 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.

作者: yinyuemi   发布时间: 2011-06-28