Using printf has a problem
Hi,
I'm trying to use printf to do some formatting. here is my code printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" "custIdPK" "custId" "prefix" "firstName" "middleName1" "middleName2" "middleName3" "lastName" "suffix" >> output.txt In my output file, here is the output custIdPK custId prefix firstName middleName1 middleName2 middleName3 lastName suffix There is suppose to be a tab between custId and prefix, but in the output it doesn't have the tab,can anyone help me out here? Thanks |
It works for me, using the Bash shell.
What shell, or what version of Linux, are you using? cheers Chris |
It works for me also.
If you do a hexdump output.txt, do you see a hex 09 character in the output? Bev. |
Works here, too:
Code:
$ printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" "custIdPK" "custId" "prefix" "firstName" "middleName1" "middleName2" "middleName3" "lastName" "suffix" >> output.txt |
Please use [code][/code] tags around your code, to preserve formatting and to improve readability.
I think your problem is simply one of appearance. Tabs are a flexible alignment character, and the actual point on the line where they line up is based on factors like the font you use and the amount of other text that comes between them. When I run your command and display the text in my shell, which uses a mono font, the two columns do indeed look like there's only about one or two spaces between them. But when I open it in kwrite, which is set to a serif font, they look far apart. To confirm that there are really tabs there, Send the output through cat -A, which will show you all non-printing characters in the text. Tabs will be indicated with "^I". Code:
cat -A output.txt |
All times are GMT -5. The time now is 08:44 AM. |