我有两个文件。
file1.txt
example1
example2
example3
file2.txt
testing1
testing2
testing3
我正在尝试将这两个文件的值连接到一个新的逗号分隔文件中,并输出
期望的输出
example1,testing1
example2,testing2
example3,testing3
任何人都可以帮助在 awk/sed 中做到这一点吗? 谢谢
最佳答案
您可以只使用粘贴
:
paste -d, file1 file2
example1,testing1
example2,testing2
example3,testing3
或者,您可以使用 awk
:
awk -v OFS=, 'FNR==NR{a[++i]=$0; next} {print a[FNR], $0}' file1 file2
example1,testing1
example2,testing2
example3,testing3
关于bash - 使用逗号分隔的 sed awk 连接两个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31228571/