Formattet output inside variable / line brak inside variable

Formattet output inside variable / line brak inside variable

Post by Michael Schinhamme » Thu, 22 Jun 2006 20:38:23



Hi everybody,

i am using the tcsh under freebsd

i want query a mysql DB wich have approx 100 entrys and generate
multiple template files.

The problem is that the direct output to a variable doesnt work there
are differences between the output into a text file and a variable.

I don't want to use a text file for data generation.

is there any possibility to preformat the variable input in that form
that i can do an echo $variable and get an output like sample OUTPUT2 ?

Regards Michael

-- Output1: directly at a tcsh
host01:/home/ux/mytest> host01:/home/ux/mytest> echo "select
id,nr,color,length,type,count(length) from patch.cable  group by
length,type,color;" | mysql -ur -pr -B

id      nr      color   length  type    count(length)
032     132     grey    1000    std     6
020     120     grey    2000    std     12
001     100     grey    3000    std     13

Output2: generated in a tcsh and written to a file

host01:/home/ux/mytest>  echo "select
id,nr,color,length,type,count(length) from patch.cable  group by
length,type,color;" | mysql -ur -pr -B > test1.txt

host01:/home/ux/mytest> less test1.txt
id      nr      color   length  type    count(length)
032     132     grey    1000    std     6
020     120     grey    2000    std     12
001     100     grey    3000    std     13

Output3 generated in a tcsh and written to a variable

host01:/home/ux/mytest> set test125=`echo "select
id,nr,color,length,type,count(length) from patch.cable  group by
length,type,color;" | mysql -ur -pr -B`

host01:/home/ux/mytest> echo $test125
id nr color length type count(length) 032 132 grey 1000 std 6 020 120
grey 2000 std 12 001 100 grey 3000 std 13

 
 
 

Formattet output inside variable / line brak inside variable

Post by Michael Tosc » Thu, 22 Jun 2006 21:10:35



> Hi everybody,

> i am using the tcsh under freebsd

> i want query a mysql DB wich have approx 100 entrys and generate
> multiple template files.

> The problem is that the direct output to a variable doesnt work there
> are differences between the output into a text file and a variable.

> I don't want to use a text file for data generation.

> is there any possibility to preformat the variable input in that form
> that i can do an echo $variable and get an output like sample OUTPUT2 ?

Always use

echo "$variable"

--


 
 
 

Formattet output inside variable / line brak inside variable

Post by Michael Tosc » Thu, 22 Jun 2006 21:18:47




>> Hi everybody,

>> i am using the tcsh under freebsd

>> i want query a mysql DB wich have approx 100 entrys and generate
>> multiple template files.

>> The problem is that the direct output to a variable doesnt work there
>> are differences between the output into a text file and a variable.

>> I don't want to use a text file for data generation.

>> is there any possibility to preformat the variable input in that form
>> that i can do an echo $variable and get an output like sample OUTPUT2 ?

> Always use

> echo "$variable"

csh/tcsh also treat the `backticks` wrong.
Use sh instead:

x=`ls`
echo "$x"

works as expected only in sh,ksh,bash,...

--

 
 
 

Formattet output inside variable / line brak inside variable

Post by Michael Schinhamme » Fri, 23 Jun 2006 16:27:12





>>> Hi everybody,

>>> i am using the tcsh under freebsd

>>> i want query a mysql DB wich have approx 100 entrys and generate
>>> multiple template files.

>>> The problem is that the direct output to a variable doesnt work there
>>> are differences between the output into a text file and a variable.

>>> I don't want to use a text file for data generation.

>>> is there any possibility to preformat the variable input in that form
>>> that i can do an echo $variable and get an output like sample OUTPUT2 ?

>> Always use

>> echo "$variable"

> csh/tcsh also treat the `backticks` wrong.
> Use sh instead:

> x=`ls`
> echo "$x"

> works as expected only in sh,ksh,bash,...

hmm this is not helpful the problem should be the input fotmat -  i want
inoput data from mysql to a variable
 
 
 

Formattet output inside variable / line brak inside variable

Post by Michael Tosc » Sat, 24 Jun 2006 01:29:35






>>>> Hi everybody,

>>>> i am using the tcsh under freebsd

>>>> i want query a mysql DB wich have approx 100 entrys and generate
>>>> multiple template files.

>>>> The problem is that the direct output to a variable doesnt work
>>>> there are differences between the output into a text file and a
>>>> variable.

>>>> I don't want to use a text file for data generation.

>>>> is there any possibility to preformat the variable input in that
>>>> form that i can do an echo $variable and get an output like sample
>>>> OUTPUT2 ?

>>> Always use

>>> echo "$variable"

>> csh/tcsh also treat the `backticks` wrong.
>> Use sh instead:

>> x=`ls`
>> echo "$x"

>> works as expected only in sh,ksh,bash,...

> hmm this is not helpful the problem should be the input fotmat -  i want
> inoput data from mysql to a variable

I thought you've got the idea.
Mapping the idea to your case:

#!/bin/sh
test125=`echo "select id,nr,color,length,type,count(length) from patch.cable  group by length,type,color;" | mysql -ur
-pr -B`
echo "$test125"

--

 
 
 

1. Problem: Shell Variable inside Variable ????


eval echo ${${A}} will work.
--


DEEP THOUGHTS, by Jack Handey                                                                      It's too bad that whole families have to be torn apart                          by something as simple as wild dogs.

2. How about this modem??

3. Evaluate a variable that is inside a string variable

4. Yggdrasil and PAS 16 SCSI

5. variable inside of variables

6. floppy

7. How do i dereference a variable inside a variable?

8. Sun 220R and A1000

9. Using symbol (variable) by awk inside script

10. substitute sh shell command inside variable

11. To use Environment Variable inside java

12. grepping for pattern with variable inside

13. HELP: How to set DISPLAY variable inside Solaris rsh command.