Linux常用基本命令(paste)

本文详细介绍了Linux下paste命令的使用方法,包括如何将多个文件按行合并、指定分隔符、以及将一个文件的奇偶行内容进行特定组合。通过实例演示了不同选项的应用场景。

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

 

转载于:https://www.cnblogs.com/ghostwu/p/9064225.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值