zoukankan      html  css  js  c++  java
  • linux命令(37):paste,合并两个文件,对应行为一行

    paste的格式为:

    paste -d -s -file1 file2

    选项的含义如下:

    -d 指定不同于空格或t a b键的域分隔符。例如用@分隔域,使用- d @。如果不指定,默认用空格分割

    -s 将每个文件合并成行而不是按行粘贴。

    - 使用标准输入。例如ls -l |paste ,意即只在一列上显示输出

    [root@localhost my_shell]# cat per1
    ID897
    ID666
    ID982
    
    [root@localhost my_shell]# cat per2
    P.Jones
    S.Round
    L.Clip
    
    [root@localhost my_shell]# paste per1 per2
    ID897   P.Jones
    ID666   S.Round
    ID982   L.Clip
     
    
    [root@localhost my_shell]# paste -s per1 per2
    ID897   ID666   ID982
    P.Jones S.Round L.Clip

    paste -d的用法

    [@bjzw_97_92 merge_bash]$ cat 123.txt
    hello
    hello
    hello
    [@bjzw_97_92 merge_bash]$ cat 456.txt
    123
    123
    123
    [@bjzw_97_92 merge_bash]$ paste 123.txt 456.txt
    hello    123
    hello    123
    hello    123
    [@bjzw_97_92 merge_bash]$ paste -d '&' 123.txt 456.txt
    hello&123
    hello&123
    hello&123
    [@bjzw_97_92 merge_bash]$

     paste A B |tr " " " "  交叉合并

    wcg@ubuntu:~/data_data/all_origin_data$ cat 123.txt 
    aa
    bb
    cc
    dd
    wcg@ubuntu:~/data_data/all_origin_data$ cat 456.txt 
    11
    22
    33
    wcg@ubuntu:~/data_data/all_origin_data$ paste 123.txt 456.txt |tr "	" "
    "
    aa
    11
    bb
    22
    cc
    33
    dd
    wcg@ubuntu:~/data_data/all_origin_data$ 
     

  • 相关阅读:
    (一〇八)iPad开发之横竖屏适配
    ZOJ 1414:Number Steps
    HDU 1391:Number Steps
    ZOJ 1871:Steps
    POJ 2590:Steps
    POJ 2629:Common permutation
    POJ 2562:Primary Arithmetic
    POJ 2505:A multiplication game
    HDU 1517:A Multiplication Game
    POJ 3650:The Seven Percent Solution
  • 原文地址:https://www.cnblogs.com/lovychen/p/6564713.html
Copyright © 2011-2022 走看看