parsing
This commit is contained in:
Submodule client-gui2 updated: d69f3b5068...e87bff759a
@@ -11,7 +11,7 @@ input=$1
|
||||
output=${2:--}
|
||||
|
||||
process_csv() {
|
||||
awk -F ',' '
|
||||
awk -F '\",\"' '
|
||||
function clean_account(value, quoted) {
|
||||
quoted = substr(value, 1, 1) == "\"" &&
|
||||
substr(value, length(value), 1) == "\""
|
||||
@@ -44,7 +44,7 @@ process_csv() {
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
OFS = ","
|
||||
OFS = FS
|
||||
}
|
||||
|
||||
{
|
||||
@@ -61,7 +61,7 @@ process_csv() {
|
||||
key = key_value(cleaned)
|
||||
|
||||
if (key == "") {
|
||||
cleaned = "\"000\""
|
||||
cleaned = "000"
|
||||
key = "000"
|
||||
}
|
||||
|
||||
|
||||
75
prod_data_parse_scripts/parse_uctovnictvo.sh
Executable file
75
prod_data_parse_scripts/parse_uctovnictvo.sh
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
|
||||
printf 'Usage: %s INPUT.csv [OUTPUT.csv]\n' "$0" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
input=$1
|
||||
output=${2:--}
|
||||
|
||||
process_csv() {
|
||||
awk -F '\",\"' '
|
||||
function clean_account(value) {
|
||||
if (length(value) > 0 && substr(value, length(value), 1) !~ /[0-9]/) {
|
||||
while (length(value) > 0 && substr(value, length(value), 1) !~ /[0-9]/) {
|
||||
value = substr(value, 1, length(value) - 1)
|
||||
}
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function zero_amount_to_empty(value) {
|
||||
if (value == "0.00") {
|
||||
return ""
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
OFS = FS
|
||||
}
|
||||
|
||||
NR == 1 {
|
||||
print
|
||||
next
|
||||
}
|
||||
|
||||
{
|
||||
cleaned = clean_account($10)
|
||||
|
||||
if (cleaned == "") {
|
||||
cleaned = "000"
|
||||
}
|
||||
|
||||
key = cleaned
|
||||
key_count[key]++
|
||||
if (!(key in key_order)) {
|
||||
key_order[key] = ++key_total
|
||||
}
|
||||
|
||||
$10 = cleaned
|
||||
$11 = zero_amount_to_empty($11)
|
||||
$12 = zero_amount_to_empty($12)
|
||||
print
|
||||
}
|
||||
|
||||
END {
|
||||
for (key in key_order) {
|
||||
if (key_count[key] > 1) {
|
||||
printf "Non-unique column 10 key: %s (%d rows)\n", key, key_count[key] > "/dev/stderr"
|
||||
}
|
||||
}
|
||||
}
|
||||
' "$input"
|
||||
}
|
||||
|
||||
if [ "$output" = "-" ]; then
|
||||
process_csv
|
||||
else
|
||||
process_csv > "$output"
|
||||
fi
|
||||
Reference in New Issue
Block a user