zoukankan      html  css  js  c++  java
  • linux系统中如何将一行数据变为一列

    1、测试数据

    [root@centos79 test]# cat a.txt
    3 s g a e f k n y

    2、xargs

    [root@centos79 test]# cat a.txt
    3 s g a e f k n y
    [root@centos79 test]# cat a.txt | xargs -n 1
    3
    s
    g
    a
    e
    f
    k
    n
    y

    3、sed

    [root@centos79 test]# cat a.txt
    3 s g a e f k n y
    [root@centos79 test]# cat a.txt | sed 's/ /
    /g'
    3
    s
    g
    a
    e
    f
    k
    n
    y

    4、tr

    [root@centos79 test]# cat a.txt
    3 s g a e f k n y
    [root@centos79 test]# cat a.txt | tr " " "
    "
    3
    s
    g
    a
    e
    f
    k
    n
    y

    5、awk

    [root@centos79 test]# cat a.txt
    3 s g a e f k n y
    [root@centos79 test]# awk '{gsub(" ", "
    "); print}' a.txt
    3
    s
    g
    a
    e
    f
    k
    n
    y

    6、awk

    [root@centos79 test]# cat a.txt
    3 s g a e f k n y
    [root@centos79 test]# awk '{for(i = 1; i <= NF; i++){printf("%s
    ", $i)}}' a.txt
    3
    s
    g
    a
    e
    f
    k
    n
    y

    7、awk

    [root@centos79 test]# cat a.txt
    3 s g a e f k n y
    [root@centos79 test]# awk 'BEGIN{RS = " "; ORS = "
    "} {print}' a.txt
    3
    s
    g
    a
    e
    f
    k
    n
    y
    
    [root@centos79 test]# awk 'BEGIN{RS = " "; ORS = "
    "} {print}' a.txt | sed '$d'
    3
    s
    g
    a
    e
    f
    k
    n
    y
  • 相关阅读:
    iptables
    apt
    cvc-elt.1: Cannot find the declaration of element 'beans'.
    di
    log
    java内存模型
    spring-jms
    JTS
    10java进阶——IO2
    17单例
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15056771.html
Copyright © 2011-2022 走看看