zoukankan      html  css  js  c++  java
  • shell脚本学习(6)awk 编排字段

    awk能取出文本字段重新编排

    1 awk的用法

    awk ‘program’ [file]

    2 其中program 可以写成 ‘parrtern {action}’    pattern 或 action可以只写一个,

     只写一个action的 ‘{print 0}’ 就执行action

     只写一个pattern  根据pattern结果,做if判断, 成立就打印数据, 

    NF是当前行数。

     

    3设置分割字段

        -F 后跟的就是分割符, 这里用的是: 输出分割后的第一列数据

    awk -F: '{print $1}' do.txt 

     

    -v OFS 是设置输出分隔符,  输出后会用** 连接两个字段

    awk -Fa -v 'OFS=**' '{print $1, $3}' do.txt 

     

    4 打印行

       采集特定的字段, 用print打印

    awk -F: '{print "yuyuyu", $1, "is really", $2}' do.txt

      

    采集特定的字段, 用printf打印

    awk -F: '{printf "yuyuyu %s is really %s
    ", $1, $2}' do.txt 

    5 awk的起始,清除操作

       BEGIN {}

        PATTERN1 {ACTION1}

        PATTERN2 {ACTION2}

      END {}

    awk 'BEGIN {FS = ":"; OFS = "**"} {print $1, $2}' do.txt

    6 查找commit id ,提取id号 不要其他信息

    awk -F 'commit' '{print $2}' test.txt

    输出这种结果

    按这样改就正常了。

    awk -F'commit ' '{if($2!="") print $2}' test.txt   

    #! /bin/bash
    cat test_id.txt|while read line
    do
    git show $line > test_result.c
    done

    再搭配上这个脚本就能把git 的具体内容都显示到文件上的了。

  • 相关阅读:
    pytorch-VGG网络
    pytorch-Alexnet 网络
    pytorch-LeNet网络
    硬链接与软链接有什么不同(ln)
    联想《拯救者》U盘UEFI启动装win7[完美激活](4)
    笔记本键盘、触控板锁定技巧(3)
    BridgePattern(23种设计模式之一)
    AdapterPattern(23种设计模式之一)
    Arduino Wire.h(IIC)库函数详解
    进制表示法
  • 原文地址:https://www.cnblogs.com/mayplestory/p/11763798.html
Copyright © 2011-2022 走看看