zoukankan      html  css  js  c++  java
  • shell脚本,awk数组之如何处理多个文件。

    [root@localhost awk]# seq 10|xargs -n 2 > file
    [root@localhost awk]# seq 10  -1 1|xargs -n 2 > file1
    [root@localhost awk]# cat file
    1 2
    3 4
    5 6
    7 8
    9 10
    [root@localhost awk]# cat file1
    10 9
    8 7
    6 5
    4 3
    2 1
    [root@localhost awk]# cat file |awk '{print $1}'
    1
    3
    5
    7
    9
    [root@localhost awk]# cat file1 |awk '{print $2}'
    9
    7
    5
    3
    1
    [root@localhost awk]# cat file |awk '{print $1}'>file3
    
    [root@localhost awk]# cat file1 |awk '{print $2}'>file4
    
    [root@localhost awk]# paste file3 file4
    1    9
    3    7
    5    5
    7    3
    9    1
    [root@localhost awk]# paste file3 file4|tr "	" " "
    1 9
    3 7
    5 5
    7 3
    9 1
    [root@localhost awk]# paste file3 file4|tr "	" " ">file5
    [root@localhost awk]# cat file5
    1 9
    3 7
    5 5
    7 3
    9 1
    
    [root@localhost awk]# awk '1' file
    1 2
    3 4
    5 6
    7 8
    9 10
    [root@localhost awk]# awk '1' file1
    10 9
    8 7
    6 5
    4 3
    2 1
    [root@localhost awk]# awk '1' file1 file1
    10 9
    8 7
    6 5
    4 3
    2 1
    10 9
    8 7
    6 5
    4 3
    2 1
    [root@localhost awk]# awk '{print NR}' file file1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@localhost awk]# awk '{print NR,FNR}' file file1
    1 1
    2 2
    3 3
    4 4
    5 5
    6 1
    7 2
    8 3
    9 4
    10 5
    [root@localhost awk]# 
    
    [root@localhost awk]# awk 'NR==FNR{a[NR]=$1}NR!=FNR{print a[FNR],$2}' file file1
    1 9
    3 7
    5 5
    7 3
    9 1
    [root@localhost awk]# 
  • 相关阅读:
    Java8 Period.between方法坑及注意事项
    mybatis入门-第一个程序
    mybatis入门-框架原理
    初识servlet--未完成
    初识servlet
    session是什么
    session工作原理简介
    笔记本维修介绍
    j2se 总结
    maven
  • 原文地址:https://www.cnblogs.com/wangyuebo/p/5836933.html
Copyright © 2011-2022 走看看