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

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



 Once again one of my silly problems ;-). I search and search for an
answer/the reason why this is happening.

$ _L="Adams, Fred, and Ken Aizawa \"The Bounds of Cognition\""
echo "// __ \$_L: |${_L}|"
_AR=($(echo "${_L}" | awk -F'\"' '{for (i=1; i<=NF; i++) print $i}' ))
_AR_L=${#_AR[@]}
echo "// __ \$_AR_L: |${_AR_L}|"
for(( _IX=0; _IX<${_AR_L}; _IX++ )); do
 echo "// __ [$_IX/$_AR_L): |${_AR[$_IX]}|"
done
// __ $_L: |Adams, Fred, and Ken Aizawa "The Bounds of Cognition"|
// __ $_AR_L: |9|
// __ [0/9): |Adams,|
// __ [1/9): |Fred,|
// __ [2/9): |and|
// __ [3/9): |Ken|
// __ [4/9): |Aizawa|
// __ [5/9): |The|
// __ [6/9): |Bounds|
// __ [7/9): |of|
// __ [8/9): |Cognition|
$

 This is the result I am looking for (probably the last empty string
could be discarded):

 // __ $_L: |Adams, Fred, and Ken Aizawa "The Bounds of Cognition"|
// __ $_AR_L: |3|
// __ [0/3): |Adams, Fred, and Ken Aizawa |
// __ [1/3): |The Bounds of Cognition|
// __ [2/3): ||

 lbrtchx


Reply to: