我想如何使用日期格式将内容拆分为多个文件,如下所示:
Test_<ID name><ddmmyyyy>.CSV
如何根据格式进行拆分?
如前所述我使用:
awk -F"," 'NR>1 {print > "Test_<ID name><ddmmyyyy>.CSV_"$1".csv"}' Original.CSV
我带着
到达那里awk -v DATE="$(date +"%d%m%Y")" -F"," 'BEGIN{OFS=","}NR>1 { gsub(/"/,"",$1); print > "Assignment_"$1"_"DATE".csv"}' Test_01012020.CSV
但是我想要包含我的列名。怎么样?
答案 0 :(得分:0)
你可以尝试在你的东西中使用variables from the shell:
_DATE=` date '+%d%m%Y' `
_ID=my_value
F_EXT=${_ID}${_DATE}
# here "var" is set to the value defined from the shell "F_EXT"
awk -v var=${F_EXT} -F"," 'NR>1 {print > "Test_" var ".CSV_"$1".csv"}' Original.CSV
(我没有拿到你的“身份证名称”,所以这里是my_value
)
如果要包含列名,请在NR==1
:
awk -v DATE="$(date +"%d%m%Y")" -F"," 'BEGIN{OFS="," } NR==1 {COLUMN_NAME=$1} NR>1 { gsub(/"/,"",$1); print > "Assignment_"$1"_"COLUMN_NAME"_"DATE".csv"}' a.txt