码迷,mamicode.com
首页 > 系统相关 > 详细

Linux常用基本命令(paste)

时间:2018-05-20 20:12:33      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:hello   指定   dev   连接   文件   你好   合并   option   符号   

paste命令

作用:合并文件

格式:

paste [option] [file]

1,把两个文件的内容,按行合并

ghostwu@dev:~/linux/paste$ ls
ghostwu1.txt  ghostwu2.txt
ghostwu@dev:~/linux/paste$ cat ghostwu1.txt 
1
2
3
4

5
6
ghostwu@dev:~/linux/paste$ cat ghostwu2.txt 
hi
hello
nihao
你好啊
how are you
fine think you
ghostwu@dev:~/linux/paste$ paste ghostwu1.txt ghostwu2.txt 
1    hi
2    hello
3    nihao
4    你好啊
    how are you
5    fine think you
6    
ghostwu@dev:~/linux/paste$ 

-d 指定分隔符

ghostwu@dev:~/linux/paste$ paste -d : ghostwu1.txt ghostwu2.txt 
1:hi
2:hello
3:nihao
4:你好啊
:how are you
5:fine think you
6:

-s 每个文件占用一行

ghostwu@dev:~/linux/paste$ paste -s ghostwu1.txt 
1    2    3    4        5    6
ghostwu@dev:~/linux/paste$ paste -s ghostwu2.txt 
hi    hello    nihao    你好啊    how are you    fine think you
ghostwu@dev:~/linux/paste$ paste -s ghostwu1.txt ghostwu2.txt 
1    2    3    4        5    6
hi    hello    nihao    你好啊    how are you    fine think you

 把一个文件的奇偶行,用=号会换行符号连接

ghostwu@dev:~/linux/paste$ cat account.txt 
hello
abc123
hello2
haha123
baby
baby123
ghostwu@dev:~/linux/paste$ paste -sd =\n account.txt > account2.txt
ghostwu@dev:~/linux/paste$ cat account2.txt 
hello=abc123
hello2=haha123
baby=baby123

 

Linux常用基本命令(paste)

标签:hello   指定   dev   连接   文件   你好   合并   option   符号   

原文地址:https://www.cnblogs.com/ghostwu/p/9064225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!