我在两个文件夹fileAn
和fileBn
中有数百个大文本文件A
和B
,我想从这两个文件夹中交换前六列每个文件。然后,我会将新文件fileCn
和fileDn
保存在文件夹C
和D
中。 A
和B
中的文件数量相同,文件长度相同。
如何使用bash或regex实现这一目标?
以下是fileA1
:
"2015-11-11 00:00:00.00",59841,0.327,3.275,1.89275,32.048,8,32,11.61
"2015-11-11 00:00:00.10",59842,0.086,3.56975,2.20325,32.10205,9,32,11.57
"2015-11-11 00:00:00.20",59843,0.26575,3.343,1.8285,32.06717,10,32,11.57
"2015-11-11 00:00:00.30",59844,-0.1915,3.28175,1.793,32.12122,11,32,11.57
fileB1
:
"2015-11-11 00:00:00.00",59841,2.48975,2.8535,-0.6575,32.13168,9
"2015-11-11 00:00:00.10",59842,2.38975,3.10525,-0.62025,32.21362,10
"2015-11-11 00:00:00.20",59843,2.224,3.09825,-0.43375,32.19968,11
"2015-11-11 00:00:00.30",59844,2.102,3.029,-0.51825,32.21539,12
新文件fileC1
,前六列fileB1
替换为fileA1
的前六列:
"2015-11-11 00:00:00.00",59841,0.327,3.275,1.89275,32.048,9
"2015-11-11 00:00:00.10",59842,0.086,3.56975,2.20325,32.10205,10
"2015-11-11 00:00:00.20",59843,0.26575,3.343,1.8285,32.06717,11
"2015-11-11 00:00:00.30",59844,-0.1915,3.28175,1.793,32.12122,12
新文件fileD1
,前六列fileA1
替换为fileB1
的前六列:
"2015-11-11 00:00:00.00",59841,2.48975,2.8535,-0.6575,32.13168,8,32,11.61
"2015-11-11 00:00:00.10",59842,2.38975,3.10525,-0.62025,32.21362,9,32,11.57
"2015-11-11 00:00:00.20",59843,2.224,3.09825,-0.43375,32.19968,10,32,11.57
"2015-11-11 00:00:00.30",59844,2.102,3.029,-0.51825,32.21539,11,32,11.57
我查看了paste
命令,但找不到将其作为批处理的方法。
答案 0 :(得分:0)
您可以使用paste
和cut
来交换两个文件中的列,
paste -d, <(cut fileA1 -d, -f1-6) <(cut fileB1 -d, -f7) > fileC1
paste -d, <(cut fileB1 -d, -f1-6) <(cut fileA1 -d, -f7-9) > fileD1