如何使用bash读取多个CSV文件并将其正确附加到另一个文件中?

时间:2019-03-26 15:30:59

标签: linux bash exec

因此,我一直在尝试制作一个程序,以读取5个CSV文件的内容,名为export n .csv。这些文件的内容需要放在名为 merged.csv 的输出文件中。我对exec感到困惑,因为我不知道该放在哪里。这是代码:

#!/bin/bash

tc=1
for file_index in `ls export*.csv`                    
do
    if [ $tc -eq 1 ]; then
        fline=`head -1 export1.csv`           
        echo $fline > merged.csv
        let "tc++"
    else
        sed 1d | while read riga; do          
            echo "$riga,$file_index" >> merged.csv
        done < $file_index
    fi
done 

问题是我不知道正确放置exec的位置。第一行必须跳过(第一次除外),因为 merged.csv 应该以第一行作为字段描述。 CSV文件的结构是这样的:第一行中的名称,姓氏,产品代码,然后是数据。但是我如何正确地循环通过它们?

1 个答案:

答案 0 :(得分:0)

尝试一下:

    let printController = UIPrintInteractionController.shared
    let printInfo = UIPrintInfo(dictionary:nil)
    printInfo.outputType = UIPrintInfo.OutputType.general
    printInfo.jobName = "My Job"
    printInfo.duplex = .none
    printController.printInfo = printInfo
    printController.delegate = self
    printController.printingItem = URL(fileURLWithPath: self.getPdfFileName())
    printController.present(animated: true, completionHandler: nil)