paste命令

paste命令测试,-d参数可以指定分隔符

对于FILE,可以有多个,我们可以同时合并多个文件,例如:paste file1 file2 file3 同时合并三个文件。

[root@data-1-2 ~]# cat t1
aaaa
bbbb
cccc
dddd
eeee
[root@data-1-2 ~]# cat t2
1111
2222
3333
4444
5555
[root@data-1-2 ~]# paste t1 t2 >t3
[root@data-1-2 ~]# cat t3
aaaa	1111
bbbb	2222
cccc	3333
dddd	4444
eeee	5555
[root@data-1-2 ~]# paste t1 t2 -d ,>t3.1
[root@data-1-2 ~]# cat t3.1
aaaa,1111
bbbb,2222
cccc,3333
dddd,4444
eeee,5555
[root@data-1-2 ~]# paste t1 t2 -d | >t3.1
paste: option requires an argument -- 'd'
Try `paste --help' for more information.
[root@data-1-2 ~]# paste t1 t2 -d |>t3.2
paste: option requires an argument -- 'd'
Try `paste --help' for more information.
[root@data-1-2 ~]# paste t1 t2 -d >t3.2
paste: option requires an argument -- 'd'
Try `paste --help' for more information.
[root@data-1-2 ~]# paste t1 t2 -d .>t3.2
[root@data-1-2 ~]# cat t3.2
aaaa.1111
bbbb.2222
cccc.3333
dddd.4444
eeee.5555
[root@data-1-2 ~]# 

  

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

[root@data-1-2 ~]# paste t1 t2 -d , -s>t3.3
[root@data-1-2 ~]# cat t3.3
aaaa,bbbb,cccc,dddd,eeee
1111,2222,3333,4444,5555
[root@data-1-2 ~]# paste t1 t2  -s>t3.4
[root@data-1-2 ~]# cat t3.4
aaaa	bbbb	cccc	dddd	eeee
1111	2222	3333	4444	5555
[root@data-1-2 ~]# 

  

paste命令还有一个很有用的选项(-)。意即对每一个(-),从标准输入中读一次数据。使用空格作域分隔符,以一个6列格式显示目录列表。方法如下: 

[root@data-1-2 ~]# ls
anaconda-ks.cfg  Documents    install.log.syslog  Public  t3    t3.3       Videos
bin4.log         Downloads    Music               t1      t3.1  t3.4
Desktop          install.log  Pictures            t2      t3.2  Templates
[root@data-1-2 ~]# ls  | paste -d" " - - - - - - 
anaconda-ks.cfg bin4.log Desktop Documents Downloads install.log
install.log.syslog Music Pictures Public t1 t2
t3 t3.1 t3.2 t3.3 t3.4 Templates
Videos     
[root@data-1-2 ~]# ls  | paste -d":" - - - - - - 
anaconda-ks.cfg:bin4.log:Desktop:Documents:Downloads:install.log
install.log.syslog:Music:Pictures:Public:t1:t2
t3:t3.1:t3.2:t3.3:t3.4:Templates
Videos:::::
[root@data-1-2 ~]# ls  | paste -d"  " - - - - - - 
anaconda-ks.cfg bin4.log Desktop Documents Downloads install.log
install.log.syslog Music Pictures Public t1 t2
t3 t3.1 t3.2 t3.3 t3.4 Templates
Videos     
[root@data-1-2 ~]# ls  | paste -d"" -
anaconda-ks.cfg
bin4.log
Desktop
Documents
Downloads
install.log
install.log.syslog
Music
Pictures
Public
t1
t2
t3
t3.1
t3.2
t3.3
t3.4
Templates
Videos

  

 

posted on 2019-03-01 22:04  nmap  阅读(444)  评论(0编辑  收藏  举报

导航