Unix Shell - Re: bash: var contains full line. How to input this data with spaces

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2005 > Re: bash: var contains full line. How to input this data with spaces





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: bash: var contains full line. How to input this data with spaces
Ed Morton

2005-03-30, 5:58 pm



Ed Morton wrote:
<snip>
> BEGIN{FS="";nv=1}{
> for (i=1;i<=NF;i++) {
> if ( $i == "\"" ) {
> quoted = !quoted
> $i = "\\" $i
> }
> if ((quoted) || ($i != " ")) {
> var = var $i
> } else if (($i == " ") && (var != "")) {
> printf "VAR%s=\"%s\"\n",++nv,var
> var = ""
> }
> }
> }END{ printf "VAR%s=\"%s\"\n",++nv,var }


And, if you want to handle tabs, etc. in the same way as the above
handles just space characters, just change it to:

BEGIN{FS="";nv=1}{
for (i=1;i<=NF;i++) {
if ( $i == "\"" ) {
quoted = !quoted
$i = "\\" $i
}
if ((quoted) || ($i !~ /[[:blank:]]/)) {
var = var $i
} else if (($i ~ /[[:blank:]]/) && (var != "")) {
printf "VAR%s=\"%s\"\n",++nv,var
var = ""
}
}
}END{ printf "VAR%s=\"%s\"\n",++nv,var }

Ed.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com