Shell合并两个文件成一个文件的两列

Shell合并两个文件成一个文件的两列

发布时间:2014-07-20   编辑:www.jquerycn.cn
Shell合并两个文件成一个文件的两列,提供了两种方法,普通shell脚本,awk脚本。
 
 

文件内容如下:
more eng.txt chi.txt 
::::::::::::::
eng.txt
::::::::::::::
semicolon
comma
delimiter
spacebar
hyphen
single quote
double quote


::::::::::::::
chi.txt
::::::::::::::
分号
逗号
定界符
空格键
连字符号
单引号
双引号

方法1、paste -d "\t" eng.txt chi.txt 
semicolon       分号
comma   逗号
delimiter       定界符
spacebar        空格键
hyphen  连字符号
single quote    单引号
double quote    双引号

方法2、或者使用awk来处理

awk 'NR==FNR{a[i]=$0;i++}NR>FNR{print a[j]" "$0;j++}' eng.txt chi.txt 
semicolon 分号
comma 逗号
delimiter 定界符
spacebar 空格键
hyphen 连字符号
single quote 单引号
double quote 双引号
hash 井号

猜你喜欢

转载自www.cnblogs.com/timxgb/p/9494814.html