zoukankan      html  css  js  c++  java
  • shell文件处理awk

    系统提供了两个待处理文件a.txtb.txt,其中文件 a.txt 中的部分内容如下:

    1. Hello
    2. My Name is Alice
    3. What is your name
    4. I am Bob
    5. I came from China
    6. Where are you from
    7. Oh my God

    文件 b.txt 中的部分内容如下:

    1. Alice is a good boy
    2. Bob is a nice man and he is one of my best friend
    3. God bless you

    将文件 a.txt 中每一行的最后一个单词作为集合 1 ;将文件 b.txt 中每一行的第一个单词作为集合 2 ;请使用 shell 语言编写程序,输出包含在集合 1 但不包含在集合 2 的所有元素。

    注意事项

    禁止使用echo手动输出或类似的方法手动输出差集。

    # NR==FNR 第一个参数b.txt
    # set[$1] 以第一列单词为索引的数组
    # !(NR==FNR) 不是第一个参数b.txt 也就是a.txt
    # $NF in set 最后一列单词包含在数组中
    awk  ' {if (NR==FNR) set[$1] = $1} {if(!(NR==FNR) && !($NF in set)) {print $NF}} ' b.txt a.txt
    Hello
    name
    China
    from
  • 相关阅读:
    MMU_段式映射
    MMU段式映射(VA -> PA)过程分析
    NOR FLASH驱动程序
    PCB上 如何显示 汉字
    poj1273 Drainage Ditches
    poj2349 Arctic Network
    poj3660 Cow Contest
    poj3259 Wormholes
    poj3159 Candies
    poj1011 Sticks
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/13869446.html
Copyright © 2011-2022 走看看