zoukankan      html  css  js  c++  java
  • 1、awk打开多个文件的方法

    转载:http://www.cnblogs.com/Berryxiong/p/6209324.html

    1、当awk读取的文件只有两个的时候,比较常用的有三种方法
    (1)awk 'NR==FNR{...}NR>FNR{...}' file1 file2

    (2)awk 'NR==FNR{...}NR!=FNR{...}' file1 file2
    (3)awk 'NR==FNR{...;next}{...}' file1 file2

    next表示下一个命令不被执行

    2、当awk处理的文件超过两个时,显然上面那种方法就不适用了。因为读第3个文件或以上时,也满足NR>FNR (NR!=FNR),显然无法区分开来。
    所以就要用到更通用的方法了:

    ARGC        The number of command line arguments (does not include
                       options to gawk, or the program source).   命令行参数的个数
    ARGIND      The index in ARGV of the current file being processed. 命令行中文件序号
    ARGV        Array of command line arguments. The array is indexed
                       from 0 to ARGC - 1. Dynamically changing the contents
                       of ARGV can control the files used for data. 命令行参数数组

     awk 'ARGIND==1{a[$1]=$2}ARGIND==2{if($0 in a){print ">"a[$0]}else{print $0}}' list OsJ.pe 

    (1)ARGIND 当前被处理参数标志: awk 'ARGIND==1{...}ARGIND==2{...}ARGIND==3{...}... ' file1 file2 file3 ...
    (2)ARGV 命令行参数数组: awk 'FILENAME==ARGV[1]{...}FILENAME==ARGV[2]{...}FILENAME==ARGV[3]{...}...' file1 file2 file3 ... 
    (3)把文件名直接加入判断: awk 'FILENAME=="file1"{...}FILENAME=="file2"{...}FILENAME=="file3"{...}...' file1 file2 file3 ...

  • 相关阅读:
    附近有什么?8款可以查周边的App
    实体店里充话费要怎么弄
    怎样买手机号?
    手机号是SIM卡的号呢,还是买手机时就带的
    网站SSL证书在线检测
    未来什么行业最赚钱
    陈安之-如何选择最赚钱的行业
    斗鱼宣布获C轮15亿融资 直播行业进入资本时代
    2016年Godaddy最新域名转出教程
    GoDaddy账户间域名转移PUSH以及ACCEPT接受域名过户方法
  • 原文地址:https://www.cnblogs.com/renping/p/9176735.html
Copyright © 2011-2022 走看看