Operating System - HP-UX
1827283 Members
3525 Online
109717 Solutions
New Discussion

Re: Interpret command results and reformat output

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

Interpret command results and reformat output

Hi

I have this command (Example)
./MyCommand

this command provide the result below
value is empty
text is red
chord is blue


I'd like to do something like

for line in $(MyCommand) ; do
echo "Info=:$line
done

The problem is that I have only one line in the output with a result like this:
Info=value is emptytext is redchord is blue

How to be sure that a CRLF will be inserted after each line from the original command ?

Thanks in advance
Bests regards
Den

5 REPLIES 5
Laurent Menase
Honored Contributor
Solution

Re: Interpret command results and reformat output


if you do a
MyCommand | od -xc
what do you get?


What do you get with:
MyCommand|wile read line
do echo "Info=:$line
done


James R. Ferguson
Acclaimed Contributor

Re: Interpret command results and reformat output

Hi Den:

Perchance are you running this on GNU/Linux under the Bash shell?

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Interpret command results and reformat output

HI (again) Den:

What is the *actual* command? What does this show?

# echo ${line}|od -a

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: Interpret command results and reformat output

As JRF already asked...
What platform/OS version/Shell is being used.

This works for me under cygwin:

# cat xx
echo aap
echo noot
echo mies
# for line in $(./xx) ; do echo "Info=:$line"; done
Info=:aap
Info=:noot
Info=:mies
#

fwiw,
Hein
Leo The Cat
Regular Advisor

Re: Interpret command results and reformat output

All Answers coming from Guys here are efficient.
Thanks a lot foxes !