我有以下CSV文件,我需要比较第二列并在第n行插入数据。
CSV:
11-AUG-17,2,85,18120.4
11-AUG-17,4,112,2920
11-AUG-17,5,23,4181.92
11-AUG-17,6,284,74767.86
输入:
11-AUG-17,3,0,0
11-AUG-17,8,0,0
欲望输出:
11-AUG-17,2,85,18120.4
11-AUG-17,4,112,2920
11-AUG-17,5,23,4181.92
11-AUG-17,8,0,0
11-AUG-17,6,284,74767.86
11-AUG-17,3,0,0
我已尝试过以下awk
命令,但它会插入所有字段,如下所示
awk -F"," 'OFS="," $2!=3{print $1,3,0,0}1;$2!=8{print $1,12,0,0};' result1.csv >result2.csv
输出上述命令:
11-AUG-17,2,85,18120.4
11-AUG-17,3,0,0
11-AUG-17,8,0,0
11-AUG-17,4,112,2920
11-AUG-17,3,0,0
11-AUG-17,8,0,0
11-AUG-17,5,23,4181.92
11-AUG-17,3,0,0
11-AUG-17,8,0,0
11-AUG-17,6,284,74767.86
11-AUG-17,3,0,0
11-AUG-17,8,0,0
提前致谢支持
答案 0 :(得分:0)
现在,根据您的说法“ 无需维护订单/顺序。只需插入任何CSV行 ”,简单cat
命令就足够了:
cat input.csv >> first.csv
最终first.csv
内容:
11-AUG-17,2,85,18120.4
11-AUG-17,4,112,2920
11-AUG-17,5,23,4181.92
11-AUG-17,6,284,74767.86
11-AUG-17,3,0,0
11-AUG-17,8,0,0