Questions tagged [printf]

The shell builtin command that formats and prints data. Questions that deal with printf command or broadly using printf syntax by programming language (like awk, PHP, perl, C++...)

printf stand for print formatted. printf is shell builtin command used to print and format data and outputs to stdout.

In addition, many programming languages like awk, C++, PHP, perl use/include printf.

Useful links:

Example of usage on this site: Why printf is better than echo?

279 questions
7
votes
1 answer

Does printf have an "engineering" notation format for numbers?

Say I have this number: 105000000, in this form I can't easily see how big it is, so using printf at a prompt I try using the "scientific" notation: % printf "%.3E" 105000000 1.050E+08 This is better but I would like to use an "engineering"…
4
votes
1 answer

Setting the column position in printf

How to fix the positions of output string in shell using printf? For example ,if I want to print text TEXT-A at position starting from third position from left and one more text TEXT-B at eleventh position from left,as shown below.
g4ur4v
  • 1,764
  • 8
  • 29
  • 34
1
vote
1 answer

print characters repetitively using asterisk symbol in bash

print '*' * 80 This python snippet prints 80 asterisks, which I use often as delimiters in log files. How can I do it in bash script using operator overloading?
user93868
0
votes
1 answer

What format to pass to printf to convert seconds to hh:mm:ss?

I'm looking at an instruction of the form: $ printf [format] $elapsed with $elapsed expressed in seconds. I want it to output 'hh:mm:ss'. I couldn't figure out format from the man. Would someone please make a suggestion?
Erwann
  • 677
0
votes
3 answers

Set printf dynamic format for trailing whitespaces

Any standard way to make the '%-6s' format for printf dynamic? function justify { echo "$(printf '%-6s' $1)" } I tried inserting variable into the format but I'm getting Error processing format error. $(printf '%-${2}s' ${1})
resti
  • 3
  • 2
0
votes
0 answers

Do printf(1) implementations differ in how they handle argument overflow?

Every instance I've found of printf(1) (that is, the command-line version; as opposed to printf(3), the C library) repeats its format-string to consume more when presented with too many arguments, allowing for constructions such as printf '%s\n'…
JamesTheAwesomeDude
  • 845
  • 3
  • 14
  • 31
0
votes
1 answer

printf "$V" fails when it's: '^+%&/%+^

To avoid \n: using "printf" rather than "echo" Set String IFS='' read -r -d '' V <<'EOF' '^+%&/%+^ EOF Test w/ echo ( works fine ) echo "$V" '^+%&/%+^ Test w/ printf ( fails ) printf "$V" bash: printf: `&': invalid format character
user217158
0
votes
1 answer

How to draw a Divider Line with Name Title before the output display

I have written a script which displays Name and department of the user and that works.Moreover i am trying to draw a divider line with Name title assign to the columns as they needed. I am trying to do it with printf but somehow not able to get it…
krock1516
  • 343
0
votes
1 answer

printf thousand separator not working on MacBook

I am using the following command on Terminal in MacBook. printf "The number is %'d\n" 123456 I expect the output: The number is 123,456. But I am getting: The number is 123456. Please point out my mistake.
0
votes
1 answer

How to print a horizontal line the size of the terminal with a word in the middle?

I need to display --------------------------- word ---------------------------- with the word right in the middle of the horizontal line and set the length of the horizontal line to that it fits the used terminal width. I thought about using a…
user123456
  • 5,018
0
votes
3 answers

Using printf to round 49.765 to 49.77?

49.765 is my output from a ring of commands. I want to use print f to round it by two decimal figures to 49.77. What is the code for it?
Shawn
  • 7