Echo not printing the variables with delimiters as required

This is the file which contains only neccessary values from the output of curl command i.e TEMP_FILE

        Proxy Hostname
        server0123.domain.com
        Proxy IP address
        XXX.XXX.XX.XX port 0000
        Proxy Version
        SGOS X.X.X.X
        Proxy Serial #
        000000001
        Client IP
        YYY.YYY.YYY.YYY
        Client Logged In As

        Groups user is member of

And here is the script which I have

#!/bin/bash

TEMP_FILE=/tmp/dashbosrd_details.txt
curl --silent --proxy <proxy_server_address:Port> --url http://dashbord.info/ | sed -e '/<d[td]\|^[[:blank:]]*$/!d; s/<[^>]*>//g; s/^ *//; /^\(Proxy\|Client\)/ s/$/:/' > $TEMP_FILE

Client_Hostname=`hostname --fqdn`
Proxy_Hostname=`awk '/Proxy Hostname/{getline;print;}' $TEMP_FILE`
Proxy_IP_address=`awk -F "port" '/Proxy IP address/{getline;print $1;}' $TEMP_FILE`
Proxy_IP_Port=`awk -F "port" '/Proxy IP address/{getline;print $2;}' $TEMP_FILE`
Proxy_Serial=`awk '/Proxy Serial #/{getline;print;}' $TEMP_FILE`
Client_IP=`awk '/Client IP/{getline;print;}' $TEMP_FILE`
Client_Logged_In_As=`whoami`


echo "$Client_Hostname" "|" "$Proxy_Hostname" "|" "$Proxy_IP_address" "|" "$Proxy_IP_Port" "|" "$Proxy_Serial" "|" "$Client_IP" "|" "$Client_Logged_In_As"

But the output of the script comes in a random or disorganized way as given below

 | <Client_Logged_In_As i.e whoami>YY.YYY.YYY.YYYort 0000 server0123.domain.com
 

Desired output:

myserver.domain.com | server0123.domain.com | XXX.XXX.XX.XX | 0000 | 000000001 | YYY.YYY.YYY.YYY | <Client_Logged_In_As i.e whoami>

This is a guess:
Your terminal output doesn't wrap and it is overwriting itself several times.

You could always test it by redirecting to a file instead of the screen.

1 Like

I tried redirecting the output to a file and then opening that file. But still I face the same problem.

For your infornmation, when I run one by one as a command and then echo those variable in the same format as given below it work completly fine.

Only when it is in the script the output is disfigured.

That file has DOS line terminators (<CR>, 0X0D). Get rid of them and it will fly.

1 Like

@RudiC:

I had this doubt because it is not a good practise to use the curl output i.e in xml directly for processing or searching.
I tried converting that using lync and xmlparser but both utilities are not available in the machine which I am working at the same time I dont have enough privileges to get that.

Can you please help me removing DOS line terminators (<CR>, 0X0D)?

e.g.

curl ... | tr -d '\r' > $TEMP_FILE