1

I am using printf command to log some values in a file as follows:

printf "Parameter = $parameter v9_value = $v9_val v9_line = $V9_Line_Count v16_val = $v16_val v16_line = $V16_Line_Count"

But the output I am getting as follows:

 v16_line = 8elayServerPort v9_value = 41 v9_line = 8 v16_val = 4571

Seems like the line is printed in rotation manner, and last values are coming from starting.

Expected Output:

Parameter = RelayServerPort v9_value = 41 v9_line = 8 v16_val = 4571 v16_line = 8

But v16_line = 8 is overwritten on Parameter = R in line.

3
  • 2
    I think some of your variables have carriage returns in them, so the output goes back to the beginning of the line and overwrites it. Commented Mar 27, 2015 at 11:05
  • Are you getting these values from a file written on a Windows machine? Commented Mar 27, 2015 at 11:06
  • 1
    If so, use dos2unix to get rid of the CR characters. Commented Mar 27, 2015 at 11:06

1 Answer 1

1

printf doesn't add a NL on the end. You need to add \n to the end of your printf.

Not seeing the rest of your program, or where you get your variable values, it's hard to say what else could be the issue.

One thing you can do is to redirect your output to a file and look at that file either through a good program editor or using cat -v which disables control characters.

See if you see ^M in your output. If you do, it could be that you have ^R in your variables.

Also remove $v16_val from your printf (temporarily) and see if your output looks better. If so, that $v16_val might have a CR (^M) in it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.