shell编程之tee命令和paste命令:数据输出命令

Posted 锦衣admin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell编程之tee命令和paste命令:数据输出命令相关的知识,希望对你有一定的参考价值。

shell编程之tee命令和paste命令:数据输出命令

tee命令:双向输出命令

作用:双向输出

用途:多路径输出

tee命令说明:

命令格式:
	#L 命令 | tee 选项 filenema
		选项说明:
			-a:双向追加重定向
		
#l		注意:tee命令从标准输入读取并写入标准输出和文件,即:双向覆盖重定向<屏幕输出|文本输入>
		
			
演示:
	# echo "hello word"
		[root@server ~]# echo "hello word"
			hello word

	# echo "hello word" | tee 3.txt				=>	不加-a选项是覆盖输入,且会新建文件
		[root@server ~]# echo "hello word" | tee 3.txt
			hello word
		[root@server ~]# cat 3.txt
			hello word

	# echo "say goodbye" | tee 3.txt			=>	不加-a选项是覆盖输入,且会新建文件
		[root@server ~]# echo "say goodbye" | tee 3.txt
			say goodbye
	# cat 3.txt		
		[root@server ~]# cat 3.txt
			say goodbye

	# echo "hello word" | tee -a 3.txt			=>-a选项则追加输入
		[root@server ~]# echo "hello word" | tee -a 3.txt
			hello word
		[root@server ~]# cat 3.txt
			say goodbye
			hello word

paste命令:多文件合并输出命令

作用:多文件打印输出(内存中处理)

用途:多文件数据合并处理

paste命令说明:

命令格式:
	# paste 选项 选项的值 filename1 filename2..
		选项说明:	
			-d:自定义分割符。默认分割符是tab键
			-s:串行处理,非并行
#l		备注:默认将多个文件并行输出


演示:
	# paste 1.txt 2.txt			=>	两个文件合并输出,默认分割符为tab键
		[root@server ~]# paste 1.txt 2.txt
			a       1
			b       2
			c       3
			d       4
			        5

	# paste -d '-' 1.txt 2.txt		=>	两个文件合并输出,-d 指定分隔符为"-"
		[root@server ~]# paste -d '-' 1.txt 2.txt
			a-1
			b-2
			c-3
			d-4
			-5

	# paste  -s 1.txt 2.txt			=>	-s 指定两个文件串行输出,默认分隔符tab键
		[root@server ~]# paste  -s 1.txt 2.txt
			a       b       c       d
			1       2       3       4       5
	
	# paste -d '-' -s 1.txt 2.txt	=>	-s 指定两个文件串行输出,-d 指定分割符为"-"
		[root@server ~]# paste -d '-' -s 1.txt 2.txt
			a-b-c-d
			1-2-3-4-5

以上是关于shell编程之tee命令和paste命令:数据输出命令的主要内容,如果未能解决你的问题,请参考以下文章

Liunx 中sed、grep、cut、sort、tee、diff 、paste命令

shell之使用paste命令按列拼接多个文件

shell命令--paste

shell中的tee命令的使用

22.Shell特殊符号和cut,sort,wc,uniq,tee,tr,split命令

shell编程之sort命令和uniq命令:数据排序去重命令