如何使用awk删除双引号 [英] How to remove double quotes using awk
本文介绍了如何使用awk删除双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的命令:
awk -v DATE="$(date +"%Y%m%d")" -F"," 'NR>1 { print > "Assignment_"$1"_"DATE".csv"}' Text_01012020.CSV
但是它是这样的:
Assignment_"A"_01012017
我要删除"___",您能帮我吗?
I want to remove "___", can you help me?
我发现了这一点
awk -v DATE="$(date +"%d%m%Y")" -F"," 'NR>1 { gsub(/"/,"",$1); print > "Assignment_"$1"_"DATE".csv"}' Text_01012020.CSV
但是运行此命令后,我的文件可以是Assignment_A_01012017,但是在我的文件内部.怎么样?
but after I run this command, my file can be assignment_A_01012017 but then inside my file..the column not seperated into column. How?
推荐答案
在awk
awk -F, -v DATE="$(date +'%Y%m%d')" 'NR>1{s=$1; gsub(/"/,"",s); print > "Assignment_"s"_"DATE".csv"}' Text_01012020.CSV
说明
awk -F, -v DATE="$(date +'%Y%m%d')" ' # Start awk, where field sep being comma
# and variable DATE with current date
NR>1{ # If no records greater than 1 then
s=$1; # save field1 data to variable s
gsub(/"/,"",s); # substitute double quote with null in variable s, so here we remove quote
# print current record/line to file Assigment_{field1}_{current_date}.csv
# {field1} = value of variable s after removing double quote
# {current_date} = value of variable DATE
print > "Assignment_"s"_"DATE".csv"
}
' Text_01012020.CSV
这篇关于如何使用awk删除双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文