Echo not printing the variables with delimiters as required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Echo not printing the variables with delimiters as required
# 1  
Old 06-22-2016
Lightbulb 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

Code:
        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

Code:
#!/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

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

Desired output:

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

# 2  
Old 06-22-2016
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.
This User Gave Thanks to Aia For This Post:
# 3  
Old 06-22-2016
Lightbulb

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.
# 4  
Old 06-22-2016
That file has DOS line terminators (<CR>, 0X0D). Get rid of them and it will fly.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 06-22-2016
@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)?

Last edited by ramprabhum; 06-22-2016 at 07:35 AM.. Reason: Spelling
# 6  
Old 06-22-2016
e.g.
Code:
curl ... | tr -d '\r' > $TEMP_FILE

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing double quotes in echo command

Please help me to use echo or printf type of command to print some value from variable within double quotes - I want to print the double quote ( " ") also. I tried #!/bin/bash VALUE=some_value echo '{"value" : "$VALUE"}' I was expecting the above script would produce .. {"value" :... (3 Replies)
Discussion started by: atanubanerji
3 Replies

2. Shell Programming and Scripting

Help required in printing in specific format

Hi All, I 'm matching two files based on the first 2 columns and then populate other fields along with subtraction of few fields. I have managed to get the output. However, is there a easier way in formatting the output as shown below instead of using additional printf for getting fixed width... (4 Replies)
Discussion started by: shash
4 Replies

3. Shell Programming and Scripting

Searching and printing only required pattern

Hi all, i am trying to count the number of logical processors from the below output: # print_manifest | grep "logical processors" 8 cores, 16 logical processors per socket 2 logical processors (2 per socket) i just want to have below output : 16 2 also... (11 Replies)
Discussion started by: omkar.jadhav
11 Replies

4. Shell Programming and Scripting

echo two variables like the paste command is not working

Dear all, I have two files like this file1 A B C D E F file2 1,2 3,4 5,6 I want this output output_expected A B 1,2 C D 3,4 E F 5,6 (3 Replies)
Discussion started by: valente
3 Replies

5. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as: user1@domain.com='user1@domain.com' user2@domain.com='user2@domain.com' user3@domain.com='user3@domain.com' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

6. Shell Programming and Scripting

Extracting variables from echo

Hello all. I can not remember the command to extract a variable from the date command. Basically what I need to do is to store the values of date in variable and rearrange them. I can not remember the command or the syntax to do so. so.. date Mon Mar 8 06:57:19 GMT 2010 $1 $2 ... (12 Replies)
Discussion started by: adelsin
12 Replies

7. Shell Programming and Scripting

Echo Variables and Text

I've been trying to get the syntax right so I can echo a $var and then text around it or after it. It either wont display text or $var or one overwrites the other at the beginning of the line. Trying to do something like this. var=1 echo $var"+1.1" #output expected 1+1.1 Its an older... (3 Replies)
Discussion started by: Grizzly
3 Replies

8. UNIX for Dummies Questions & Answers

Help required on Printing of Numbers, which are missing in the range

Hi Experts, Need help on printing of numbers, which are missing in the range. Pls find the details below Input 1000000002 1000000007 1234007940 1234007946 Output 1000000003 1000000004 1000000005 1000000006 1234007941 (2 Replies)
Discussion started by: krao
2 Replies

9. Shell Programming and Scripting

Help required on grep command(Skip the first few lines from printing in the output)

Hi experts I want the proper argument to the grep command so that I need to skip the first few lines(say first 10 lines) and print all the remaining instances of the grep output. I tried to use grep -m 10 "search text" file*. But this gives the first 10 instances(lines) of the search string.... (7 Replies)
Discussion started by: ks_reddy
7 Replies

10. UNIX for Dummies Questions & Answers

Help required on printing the line if third field is not a empty space

Hi Experts, I want to print the lines whose third field in non-empty/blank space. i.e. INPUT FILE/B] dcdccghjrry0yd cont dcdccttrk820529 cont rdekedfsSCr dcdccttrdky2d0y cont rdekedfsSC2 ... (3 Replies)
Discussion started by: krao
3 Replies
Login or Register to Ask a Question