按列拼接文件
同学问下如何按列拼接文件,脚本中写了三种方法……
#! /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}