将一个文件的多行附加到另一个文件

时间:2019-11-23 18:07:12

标签: excel awk sed grep notepad++

大家好,

我有两个文件,它们具有相同的行数(精确地为503),并且我想将一个文件的内容附加到文件的另一右前方,而没有任何空格或制表符。让我们考虑输入文件的内容是:

One.txt

C:\Users\Desktop.VG\New-folder\?filename=
C:\Users\Desktop.VG\New-folder\?filename=
C:\Users\Desktop.VG\New-folder\?filename=
C:\Users\Desktop.VG\New-folder\?filename=
C:\Users\Desktop.VG\New-folder\?filename=

Two.txt

one
val_ilu_girl
pacmanhall
four_stars
squares3

现在我要这样:

C:\Users\Desktop.VG\New-folder\?filename=one
C:\Users\Desktop.VG\New-folder\?filename=val_ilu_girl
C:\Users\Desktop.VG\New-folder\?filename=pacmanhall
C:\Users\Desktop.VG\New-folder\?filename=four_stars
C:\Users\Desktop.VG\New-folder\?filename=squares3
  

是否可以使用从SED GREP AWKEXCEL Notepadd++等的任何方式来做到这一点? < / p>

预先感谢...!

2 个答案:

答案 0 :(得分:2)

请您尝试以下。

awk 'FNR==NR{a[FNR]=$0;next} {print $0 a[FNR]}'  two.txt one.txt

说明: 添加上述代码的说明。

awk '                   ##Starting awk program here.
FNR==NR{                ##Checking condition FNR==NR which will be TRUE when first Input_file is being read.
  a[FNR]=$0             ##Creating an array named a whose index is FNR and value is current line.
  next                  ##next will skip all further statements from here.
}                       ##Closing BLOCK for FNR==NR condition here.
{                       ##These statements will be executed when 2nd Input_file is being read.
  print $0 a[FNR]       ##Printing current line along with array a value with index of FNR.
}
'  two.txt one.txt      ##Mentioning Input_file names here.

答案 1 :(得分:2)

那是发明工作paste的目的:

$ paste -d '' one.txt two.txt
C:\Users\Desktop.VG\New-folder\?filename=one
C:\Users\Desktop.VG\New-folder\?filename=val_ilu_girl
C:\Users\Desktop.VG\New-folder\?filename=pacmanhall
C:\Users\Desktop.VG\New-folder\?filename=four_stars
C:\Users\Desktop.VG\New-folder\?filename=squares3