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
  • 相关阅读:
    继承ServletContextListener可以完成的事情
    redis-win7
    jquery-attr与prop
    web表单disable问题
    html-select
    wordpress安装五步法
    CSS布局整理
    photoshop制作古风画
    CSS布局——三栏布局
    sublime text3配置插件
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15056771.html
Copyright © 2011-2022 走看看