按列拼接文件

同学问下如何按列拼接文件,脚本中写了三种方法……

#! /bin/bash                                                                                                       

len1=`wc -l $1 | cut -d ' ' -f1`
len2=`wc -l $2 | cut -d ' ' -f1`

file1=$1
file2=$2


if [ ${len1} -le ${len2} ]
then
    file1=$2
    file2=$1
fi

#paste ${file1} ${file2} 
#awk '{a="NULL"; getline a < "'${file2}'";print $0, a}' ${file1} 
awk 'NR == FNR {a[i] = $0; i++} NR > FNR{print $0" "(a[j] ? a[j] : "NULL"); j++}' ${file2} ${file1}

 

posted on 2013-07-21 16:50  阿加  阅读(204)  评论(0编辑  收藏  举报

导航