LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash format "cat" output (https://www.linuxquestions.org/questions/linux-general-1/bash-format-cat-output-248639/)

bendeco13 10-29-2004 12:29 AM

bash format "cat" output
 
I'm using the --colorsel option from Xdialog and giving the output to a variable using the "cat" function.
what's happening is the Xdialog program is letting the user select a color.
Then I assigned this to a file using 2>"FILE" then I'm using the cat function to read this file into a variable. Then I echo the variable and....

The output looks like this:
244 122 255

but I need it to look like this:
244, 122, 255

Is there a way to get it to read untill a space is encountered and then assign this a variable, then read untill the next space is encountered....ext...ext....?

anyone know how to do this?
thanks in advance!!

bigrigdriver 10-29-2004 01:30 AM

You could probably pipe the output through either sed or awk to search for <space> and replace that with <comma><space>.
Use google to search for sed and awk examples.

bendeco13 10-29-2004 01:55 AM

Thanks Alot!!!!
I ended up using awk.
Here's what I had to do:
Code:

DIALOG=Xdialog
$DIALOG --rc-file $SKIN --colorsel "Select A Color" 0 0 2>/tmp/checklist-audiotools.tmp.$$
COLOR1a=`awk '{ printf $1 }' /tmp/checklist-audiotools.tmp.$$`
COLOR1b=`awk '{ printf $2 }' /tmp/checklist-audiotools.tmp.$$`
COLOR1c=`awk '{ printf $3 }' /tmp/checklist-audiotools.tmp.$$`
rm -f /tmp/checklist-audiotools.tmp.$$
COLOR1="{ $COLOR1a, $COLOR1b, $COLOR1c}"


/bin/bash 10-29-2004 06:39 AM

Look at THIS thread.


All times are GMT -5. The time now is 01:08 PM.