入世对命令行与列粘贴或PR不工作 [英] Joining Columns on Command Line with Paste or PR Not Working
问题描述
所以,我有我要带出列,并在一个文件中加入他们两个文件。
So I have two files that I want to take columns out of and join them in a single file.
F1:
02/10/2013,16:00:00.091,123.82,OTCX,GLO,,123.82
02/10/2013,16:00:03.072,123.766,FXN,NAM,,123.766
02/10/2013,16:00:03.491,123.769,FXN,,,123.769
02/10/2013,16:00:03.565,123.79,COMM,ASI,HKG,123.79
02/10/2013,16:00:03.721,123.769,FXN,NAM,NYC,123.769
02/10/2013,16:00:04.194,123.81,AKM,EUR,MOW,123.81
02/10/2013,16:00:06.130,123.764,FXN,NAM,NYC,123.764
02/10/2013,16:00:06.330,123.764,FXN,,,123.764
02/10/2013,16:00:08.989,123.766,FXN,,,123.766
02/10/2013,16:00:09.034,123.791,FXN,,,123.791
F2:
02/10/2013,16:00:00.091,123.82,123.83,OTCX,GLO,
02/10/2013,16:00:03.072,123.766,123.888,FXN,NAM,
02/10/2013,16:00:03.491,123.769,123.888,FXN,,
02/10/2013,16:00:03.565,123.79,123.87,COMM,ASI,HKG
02/10/2013,16:00:03.721,123.769,123.891,FXN,NAM,NYC
02/10/2013,16:00:04.194,123.81,123.85,AKM,EUR,MOW
02/10/2013,16:00:06.130,123.764,123.891,FXN,NAM,NYC
02/10/2013,16:00:06.330,123.764,123.888,FXN,,
02/10/2013,16:00:08.989,123.766,123.886,FXN,,
02/10/2013,16:00:09.034,123.791,123.861,FXN,,
只见参照previous SO的问题在这里:<一href=\"http://stackoverflow.com/questions/16910057/how-to-paste-columns-from-separate-files-using-bash\">How粘贴使用bash从单独的文件列?
但由于某种原因都在粘贴和公关命令不工作的这组数据:代替粘贴-d≤(切-d,-f 3,7 F1)≤(猫F2)
只是附加一个逗号的F2每一行的前面
but for some reason both the paste and the pr commands are not working for this data set: instead paste -d <(cut -d "," -f 3,7 f1) <(cat f2)
just appends a comma to the front of every line of f2
,02/10/2013,16:00:00.091,123.82,123.83,OTCX,GLO,
,02/10/2013,16:00:03.072,123.766,123.888,FXN,NAM,
,02/10/2013,16:00:03.491,123.769,123.888,FXN,,
,02/10/2013,16:00:03.565,123.79,123.87,COMM,ASI,HKG
,02/10/2013,16:00:03.721,123.769,123.891,FXN,NAM,NYC
,02/10/2013,16:00:04.194,123.81,123.85,AKM,EUR,MOW
,02/10/2013,16:00:06.130,123.764,123.891,FXN,NAM,NYC
,02/10/2013,16:00:06.330,123.764,123.888,FXN,,
,02/10/2013,16:00:08.989,123.766,123.886,FXN,,
,02/10/2013,16:00:09.034,123.791,123.861,FXN,,
公关-mts,
产生相同的行为粘贴。
pr -mts,
yields the same behavior as paste.
为什么这些文件是不同的行为有什么建议?
Any advice on why these files are behaving differently?
谢谢!
推荐答案
请注意,你错过了给 -d
选项的值。
Note that you missed giving the -d
option a value.
要投入3列和第7在F2行开始,用逗号隔开
To put columns 3 and 7 at the beginning of "f2" lines, separated with a comma
paste -d, <(cut -d, -f 3,7 f1) f2
占CRLF行结束
Accounting for CRLF line endings
paste -d, <(sed 's/\r$//' f1 | cut -d, -f 3,7) <(sed 's/\r$//' f2)
这篇关于入世对命令行与列粘贴或PR不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!