[英]How can I copy columns from several files into the same output file using Perl
This is my problem. 这是我的问题。
I need to copy 2 columns each from 7 different files to the same output file. 我需要将2列从7个不同的文件复制到相同的输出文件。 All input and output files are CSV files.
所有输入和输出文件均为CSV文件。 And I need to add each new pair of columns beside the columns that have already been copied, so that at the end the output file has 14 columns.
我需要在已复制的列旁边添加每对新列,以便最后输出文件具有14列。
I believe I cannot use 我相信我不能使用
open(FILEHANDLE,">>file.csv").
Also all 7 CSV files have nearlly 20,000 rows each, therefore I'm reading and writing the files line by line. 另外,所有7个CSV文件每个都有近20,000行,因此我正在逐行读取和写入文件。
It would be a great help if you could give me an idea as to what I should do. 如果您能给我一个关于我应该做什么的想法,那将是一个很大的帮助。
Thanx a lot in advance. 非常感谢。
Provided that your lines are 1:1 (Meaning you're combining data from line 1 of File_1, File_2, etc): 假设您的行是1:1(意味着您要合并来自File_1,File_2等的第1行的数据):
Text::CSV is probably the way to access CSV files. Text :: CSV可能是访问CSV文件的方法。
You could define a csv handler for each file (including output), use getline
or getline_hr
(returns hashref) methods to fetch data, combine it into arrayrefs, than use print
. 您可以为每个文件(包括输出)定义一个csv处理程序,使用
getline
或getline_hr
(返回hashref)方法来获取数据,将其组合为arrayrefs,而不是使用print
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.