[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: awk not just using the Field separator as such. it is using the blank space as well ...



On 2/15/23, DdB <debianlist@potentially-spam.de-bruyn.de> wrote:
> $ echo "Adams, Fred, and Ken Aizawa \"The Bounds of Cognition\"" | awk
> -F'\"' '{for (i=1; i<=NF; i++) print $i;}'
> Adams, Fred, and Ken Aizawa
> The Bounds of Cognition

 yes and this also works:

_L="Adams, Fred, and Ken Aizawa \"The Bounds of Cognition\""
echo "${_L}" | awk -F'\"' '{for (i=1; i<=NF; i++) print $i;}'
Adams, Fred, and Ken Aizawa
The Bounds of Cognition

 but I wasn't able to write the output into an array

> $ awk --version

 I also discovered that there seems to be something wrong with the
version of awk I am working:

$ awk --version
awk: not an option: --version

$ which awk
/usr/bin/awk

$ awk -W version
mawk 1.3.4 20200120
Copyright 2008-2019,2020, Thomas E. Dickey
Copyright 1991-1996,2014, Michael D. Brennan

random-funcs:       srandom/random
regex-funcs:        internal
compiled limits:
sprintf buffer      8192
maximum-integer     2147483647
$

On 2/15/23, David <bouncingcats@gmail.com> wrote:
> Start reading here:
>   http://mywiki.wooledge.org/BashFAQ/005

 which helped me find a hack around it I am comfortable with:

_DT=$(date +%Y%m%d%H%M%S)
_TMPFL=$(basename "$(pwd)")_$(mktemp ${_DT}.XXXXXX)

_L="Adams, Fred, and Ken Aizawa \"The Bounds of Cognition\""
echo "${_L}" | awk -F'\"' '{for (i=1; i<=NF; i++) print $i;}' > "${_TMPFL}"

mapfile -t _AR < "${_TMPFL}"
_AR_L=${#_AR[@]}
echo "// __ \$_AR_L: |${_AR_L}|"

rm --force --verbose "${_TMPFL}"

 I think the problem is whatever bash is using as "awk" is also
including a blank space as delimiter for the splitting of the string

lbrtchx


Reply to: