将两个文件粘贴到 bash(并排列)

Paste two files in bash (columns side by side)

我在 bash

中使用粘贴命令时遇到一些问题

我有一堆共享第 2 列和第 3 列的三个逗号分隔的列文本文件。首先,我通过从单个数据文件中提取此共享列来创建一个 txt 文件

awk 'BEGIN { FS = "," }{ print  "," }' file01.txt > msg-coord.txt

然后我运行通过循环获取列表中每个文件的第一列

for hora
in 00 01 02 03
do

awk 'BEGIN { FS = "," }{ print  }' file$hora.txt > a$hora.txt

done

然后尝试粘贴所有新文件(运行没问题)

paste -d "," a{00..03}.txt > temporal.txt

并通过粘贴命令添加 msg-coord.txt,这不起作用,我找不到原因

paste -d "," msg-coord.txt temporal.txt > msgdata.txt

head msgdata.txt 的输出产生

,-0.0127,-0.1773,-0.3749,-0.3780 
,-0.0318,-0.1941,-0.3780,-0.3877
,-0.0510,-0.2109,-0.3807,-0.3973
,-0.0703,-0.2277,-0.3833,-0.4068
,-0.0900,-0.2450,-0.3864,-0.4168
,-0.1101,-0.2632,-0.3903,-0.4272

缺少 msg-coord.txt 中的两列。

fileXX.txt长得像

 -0.3686,-12.5000,33.5000
 -0.3877,-12.5000,33.5800
 -0.3973,-12.5000,33.6200
 -0.4068,-12.5000,33.6600
 -0.4168,-12.5000,33.7000
 -0.4272,-12.5000,33.7400
 -0.4382,-12.5000,33.7800
 -0.4504,-12.5000,33.8200
 -0.4638,-12.5000,33.8600

在合并数据文件之前从数据文件中删除 DOS 行结尾(file*.txt?)。