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

#! /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}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2021-08-02
  • 2021-05-15
  • 2022-12-23
  • 2021-12-09
  • 2021-06-27
  • 2021-06-01
相关资源
相似解决方案