我需要有关CSV文件输出的帮助,我相信我的格式正确。
这是我的CSV文件:
Account number (preferred / formatted),Customer reference,Posting date,Account currency,Transaction amount
750856653,233420,3/9/2019,USD,-2092.99
750856653,233417,3/9/2019,USD,-2856.15
750856653,233426,3/9/2019,USD,-2392.25
750856653,233414,3/9/2019,USD,-1733.22
我的代码:
#!/bin/bash
input=".file path/input.csv"
while IFS=, read -r -a inputdata
do
[[ ${inputdata[0]} =~ ^Account ]] && continue
[[ ${inputdata[1]} == NONREF ]] && continue
[[ ${inputdata[1]} == NONREF ]] && inputdata[1]="0"
[[ ${inputdata[4]:0:1} == - ]] && Sign="-" || Sign="+"
IFS=/ read -a datestamp <<<${inputdata[2]}
printf "%s %010d %02d%02d%02d%s%012d\n" \
"${inputdata[0]:0:3}-${inputdata[0]:3:5}-${inputdata[0]:(-1)}" \
"${inputdata[1]}" \
"${datestamp[1]}" "${datestamp[0]}" "${datestamp[2]:(-2)}" \
"${Sign}" \
"${inputdata[4]//[.-]}"
done < "${input}"
所需的输出:
750-85665-3 0000233420 090319000000209299
750-85665-3 0000233417 090319000000285615
750-85665-3 0000233445 093019000000172261
750-85665-3 0000233436 093019000000169141
750-85665-3 0000233440 093019000000099289
750-85665-3 0000233459 093019000000391856
我的CSV文件:
Account number (preferred / formatted),Customer reference,Posting date,Account currency,Transaction amount
750856653,233420,3/9/2019,USD,-2092.99
750856653,233417,3/9/2019,USD,-2856.15
750856653,233426,3/9/2019,USD,-2392.25
答案 0 :(得分:0)
编辑: :能否请您按照修改后的请求进行操作。
@Component
public class StringToDocumentTypesConverter implements Converter<String, DocumentTypes> {
@Autowired
private ObjectMapper mapper;
@Override
public DocumentTypes convert(String s) {
try {
return mapper.readValue(String.format("\"%s\"", s), DocumentTypes.class);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
请您尝试以下。
ObjectMapper
说明: 添加上述代码的说明。
awk '
BEGIN{
FS=","
}
FNR==1{
print
next
}
{
$1=substr($1,1,3)"-"substr($1,4,5)"-"substr($1,length($1))
split($3,array,"/")
$3=sprintf("%02d%02d%s",array[2],array[1],array[3])
gsub(/^-|\./,"",$NF)
$3=$3"000000"$NF
print $1,"NONREF",$3
}
' Input_file