possibilité de mettre en échappement les valeurs vides
This commit is contained in:
parent
57515be0cd
commit
94bef1d7b1
|
@ -1 +1 @@
|
|||
007020002
|
||||
007021000
|
||||
|
|
|
@ -579,7 +579,7 @@ function unquote_vsep(value, vsep, hvsep) {
|
|||
'
|
||||
|
||||
function tl_format() {
|
||||
local args show_headers asep vsep qsep escape shell cmd begincmd endcmd localvars
|
||||
local args show_headers asep vsep qsep qempty escape shell cmd begincmd endcmd localvars
|
||||
show_headers=
|
||||
asep=$'\t'
|
||||
vsep=';'
|
||||
|
@ -589,6 +589,8 @@ function tl_format() {
|
|||
-F: asep= \
|
||||
-R: vsep= \
|
||||
--quote: qsep= \
|
||||
--quote-empty qempty=::EMPTY:: \
|
||||
--empty-value: qempty= \
|
||||
--escape: escape \
|
||||
-e shell \
|
||||
-c: cmd= \
|
||||
|
@ -613,7 +615,7 @@ function tl_format() {
|
|||
done
|
||||
local match_attr="$(def_match_attr "${attrs[@]}")"
|
||||
|
||||
awkrun -f show_headers:int="$show_headers" asep="$asep" vsep="$vsep" qsep="$qsep" escape="$escape" \
|
||||
awkrun -f show_headers:int="$show_headers" asep="$asep" vsep="$vsep" qsep="$qsep" qempty="$qempty" escape="$escape" \
|
||||
shell:int="$shell" cmd="$cmd" begincmd="$begincmd" endcmd="$endcmd" localvars:int="$localvars" \
|
||||
attrs[@] mapattrs[@] "$__AWK_VSEP_FUNCTIONS"'
|
||||
function reset_values() {
|
||||
|
@ -677,6 +679,7 @@ function dump_values(atbegin, value) {
|
|||
attr = norm_attr(attrs[i])
|
||||
if (i > 1) line = line asep
|
||||
value = values[attr]
|
||||
if (value == "") value = qempty
|
||||
if (qsep != "" && index(value, qsep) != 0) {
|
||||
if (escape) gsub(qsep, quote_subrepl(escape) "&", value);
|
||||
else gsub(qsep, "&&", value);
|
||||
|
@ -760,17 +763,20 @@ function tl_formatcsv() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
tl_format ${show_headers:+--show-headers} -F , -R "$vsep" --quote "$qsep" --escape "$escape" "$@"
|
||||
tl_format ${show_headers:+--show-headers} -F , -R "$vsep" --quote "$qsep" --quote-empty --escape "$escape" "$@"
|
||||
}
|
||||
|
||||
function tl_parsecsv() {
|
||||
local -a args headers
|
||||
local basedn= rdnattr= skip_lines=0 parse_headers= vsep=';'
|
||||
local basedn= rdnattr= skip_lines=0 parse_headers= vsep=';' qempty=::EMPTY::
|
||||
if parse_opts \
|
||||
-u:,--rdnattr: rdnattr= \
|
||||
-s:,--skip-lines: skip_lines= \
|
||||
-h,--parse-headers parse_headers=1 \
|
||||
-R: vsep= \
|
||||
--no-parse-empty qempty= \
|
||||
--parse-empty qempty=::EMPTY:: \
|
||||
--empty-value: qempty= \
|
||||
@ args -- "$@"; then
|
||||
set -- "${args[@]}"
|
||||
else
|
||||
|
@ -789,7 +795,7 @@ function tl_parsecsv() {
|
|||
awkrun -f \
|
||||
basedn="$basedn" rdnattr="$rdnattr" \
|
||||
skip_lines:int="$skip_lines" parse_headers:int="$parse_headers" headers[@] \
|
||||
vsep="$vsep" "$__AWK_VSEP_FUNCTIONS"'
|
||||
vsep="$vsep" qempty="$qempty" "$__AWK_VSEP_FUNCTIONS"'
|
||||
NR <= skip_lines { next }
|
||||
parse_headers {
|
||||
array_parsecsv(headers, $0)
|
||||
|
@ -803,19 +809,23 @@ parse_headers {
|
|||
rdnvalue = attrvalues[rdnindex]
|
||||
if (basedn != "") {
|
||||
print "dn: " rdnattr "=" rdnvalue "," basedn
|
||||
} else if (rdnattr != "dn") {
|
||||
print "dn: " rdnattr "=" rdnvalue
|
||||
} else {
|
||||
print "dn: " rdnvalue
|
||||
}
|
||||
for (i = 1; i <= headers_count; i++) {
|
||||
attr = headers[i]
|
||||
if (basedn == "" && attr == rdnattr) {
|
||||
if (basedn == "" && rdnattr == "dn" && attr == rdnattr) {
|
||||
continue # ne pas écrire deux fois le même attribut
|
||||
}
|
||||
attrvalue = attrvalues[i]
|
||||
split(attrvalue, values, vsep)
|
||||
values_count = array_len(values)
|
||||
for (j = 1; j <= values_count; j++) {
|
||||
print attr ": " unquote_vsep(values[j], vsep)
|
||||
value = unquote_vsep(values[j], vsep)
|
||||
if (value == qempty) value = ""
|
||||
print attr ": " value
|
||||
}
|
||||
}
|
||||
print ""
|
||||
|
@ -825,12 +835,15 @@ parse_headers {
|
|||
|
||||
function tl_parsecsvmod() {
|
||||
local -a args headers
|
||||
local basedn= rdnattr= skip_lines=0 parse_headers= vsep=';'
|
||||
local basedn= rdnattr= skip_lines=0 parse_headers= vsep=';' qempty=::EMPTY::
|
||||
if parse_opts \
|
||||
-u:,--rdnattr: rdnattr= \
|
||||
-s:,--skip-lines: skip_lines= \
|
||||
-h,--parse-headers parse_headers=1 \
|
||||
-R: vsep= \
|
||||
--no-parse-empty qempty= \
|
||||
--parse-empty qempty=::EMPTY:: \
|
||||
--empty-value: qempty= \
|
||||
@ args -- "$@"; then
|
||||
set -- "${args[@]}"
|
||||
else
|
||||
|
@ -849,7 +862,7 @@ function tl_parsecsvmod() {
|
|||
awkrun -f \
|
||||
basedn="$basedn" rdnattr="$rdnattr" \
|
||||
skip_lines:int="$skip_lines" parse_headers:int="$parse_headers" headers[@] \
|
||||
vsep="$vsep" "$__AWK_VSEP_FUNCTIONS"'
|
||||
vsep="$vsep" qempty="$qempty" "$__AWK_VSEP_FUNCTIONS"'
|
||||
NR <= skip_lines { next }
|
||||
parse_headers {
|
||||
array_parsecsv(headers, $0)
|
||||
|
@ -897,7 +910,9 @@ parse_headers {
|
|||
split(attrvalue, values, vsep)
|
||||
values_count = array_len(values)
|
||||
for (j = 1; j <= values_count; j++) {
|
||||
print attr ": " unquote_vsep(values[j], vsep)
|
||||
value = unquote_vsep(values[j], vsep)
|
||||
if (value == qempty) value = ""
|
||||
print attr ": " value
|
||||
}
|
||||
print "-"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue