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

    1、测试数据 测试1

    [root@centos7 test2]# cat a.txt
    01 02 03 04 05 06 07 08 09 10

    2、测试2

    [root@centos7 test2]# cat a.txt
    01 02 03 04 05 06 07 08 09 10
    [root@centos7 test2]# cat a.txt | xargs -n 1
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10

    3、测试3

    [root@centos7 test2]# cat a.txt
    01 02 03 04 05 06 07 08 09 10
    [root@centos7 test2]# cat a.txt | sed 's/ /\n/g'
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10

    4、测试4

    [root@centos7 test2]# cat a.txt
    01 02 03 04 05 06 07 08 09 10
    [root@centos7 test2]# cat a.txt | tr " " "\n"
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10

    5、测试5

    [root@centos7 test2]# cat a.txt
    01 02 03 04 05 06 07 08 09 10
    [root@centos7 test2]# awk BEGIN{RS=EOF}'{gsub(" ","\n");print}' a.txt
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10

    6、测试6

    [root@centos7 test2]# cat a.txt
    01 02 03 04 05 06 07 08 09 10
    [root@centos7 test2]# awk '{for(i = 1; i <= NF; i++) {printf("%s\n",$i)}}' a.txt
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10

    7、测试7

    [root@centos7 test2]# cat a.txt
    01 02 03 04 05 06 07 08 09 10
    [root@centos7 test2]# awk 'BEGIN{RS=" ";ORS="\n"}{print}' a.txt | head -n -1
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
  • 相关阅读:
    php-基于面向对象的MySQL类
    php-迭代创建级联目录
    php-删除非空目录
    php-递归创建级联目录
    linux 用户管理
    mysql 语法大全
    dos命令下修改mysql密码的方法
    对 linux init.d的理解
    linux 重启服务器命令
    校验软件包
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14703282.html
Copyright © 2011-2022 走看看