摘要:我有近500个 *.csv文件,我需要合并成一个csv文件,在合并过程中,每个csv的文件名需要添加到新列的每行中。
我在这里读到了很多关于stackoverflow和其他的线程。我正在尝试在终端中做这个(不是我在终端中运行的脚本)。这里是我到目前为止所得到的。当我运行这个终端时,它返回“for quote〉”,并且没有完成。我希望有人能很容易地指导我。
for f in *.csv; do awk -f ' { x=1 ; if ( x == NR ) { print "date,ProductNumber,Brand,Description,Size,UnitType,Pack,UPC,Available,Status,Delivery Due Date" } else { gsub(".csv","",FILENAME); print FILENAME","$0 } } “$f” > “output$f”; done
每个csv文件的结构都相同,下面是一些示例数据:
ProductNumber,Brand,Description,Size,UnitType,Pack,UPC,Available,Status,Delivery Due Date
="0100503","BARNEY BUTTER","ALMOND BTR,SMOOTH","16 OZ ","CS"," 6",="0094922553584"," 99","Active"," "
="0100701","NATRALIA","BODY LOTION,DRY SKIN","8.45 FZ ","EA"," 1",="0835787000765"," 33","Active"," "
="0101741","SAN PELLEGRINO","SPRKLNG BEV,ARANCIATA,ROS","6/11.15F","CS"," 4",="0041508300360"," 0","Active"," "
2条答案
按热度按时间kwvwclae1#
如果列表中的文件太长,则
velaa5lx2#
这对我很有效。保留第一个文件的第一行/头,并为保存文件名的列添加一个头,然后转储所有文件。