diff --git a/uawk b/uawk index 903ae49..4f11ae4 100755 --- a/uawk +++ b/uawk @@ -19,7 +19,7 @@ if [ "$scriptname" == "awkcsv" ]; then note: ce script ne tient pas compte de la locale: il travaille avec LANG=C USAGE - $scriptname [-b before] -e script [-a after] [headers...] + $scriptname [-b before] -e script [-a after] [headers...] [-- inputfiles...] $__AWKCSV_HELP" @@ -30,7 +30,7 @@ elif [ "$scriptname" == "awkfsv2csv" ]; then note: ce script ne tient pas compte de la locale: il travaille avec LANG=C USAGE - $scriptname [header:sizes...] + $scriptname [header:sizes...] [-- inputfiles...] $__AWKFSV2CSV_HELP" diff --git a/ulib/awk b/ulib/awk index 8756383..a649925 100644 --- a/ulib/awk +++ b/ulib/awk @@ -690,8 +690,15 @@ function lawkcsv() { qchar="${qchar:0:1}" echar="${echar:0:1}" - [ -n "$*" ] && headers=("$@") + headers=() + while [ $# -gt 0 -a "$1" != "--" ]; do + array_add headers "$1" + shift + done + shift + [ -n "${headers[*]}" ] || parse_headers=1 + if [ -n "$fieldmap" ]; then awkscript="$awkscript"'{ if (do_once("mapfields")) { mapfields(fields2map) } @@ -746,7 +753,7 @@ $awkscript $append_awkscript $afterscript $append_afterscript -" +" -- "$@" } function cawkcsv() { LANG=C lawkcsv "$@"; } @@ -785,7 +792,10 @@ function lawkfsv2csv() { local -a headers starts sizes local headersize header i size i=1 - for headersize in "$@"; do + while [ $# -gt 0 -a "$1" != "--" ]; do + headersize="$1" + shift + splitpair "$headersize" header size [ -n "$header" ] || { eerror "header est requis" @@ -799,6 +809,7 @@ function lawkfsv2csv() { fi i="$(($i + $size))" done + shift awkrun -f \ skip_lines:int="$skip_lines" show_headers:int="$show_headers" \ @@ -819,7 +830,7 @@ NR <= skip_lines { next } formatcsv() print } -' +' -- "$@" } function cawkfsv2csv() { LANG=C lawkfsv2csv "$@"; }