我在linux下使用join命令,但是不同机器的结果不同。我有两个简单的文件:
cat 1.txt
a aaa,0.2
b bbb,0.3
c ccc,0.5
cat 2.txt
a aaa,0.2
b bbb,0.3
c ccc,0.6
我正在运行以下命令
join -a 1 -1 1 -2 1 -t "," -o 1.1' '1.2' '2.2 <(cat 1.txt| sort -t ",") <(cat 2.txt| sort -t ",")
机器 1 上的结果:
,0.2a,0.2
,0.3b,0.3
,0.6c,0.5
join --version
join (GNU coreutils) 8.13
locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
机器2上的结果:
a aaa,0.2,0.2
b bbb,0.3,0.3
c ccc,0.5,0.6
join --version
join (GNU coreutils) 5.97
locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
显然,第一台机器上的结果是错误的。它已被截断。我尝试使用不同的区域设置但没有成功。
答案1
使用 修复您的文件dos2unix
,或者如果未安装:
sed -i 's/\r$//' {1,2}.txt