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++...)
293 questions
2
votes
1
answer
192
views
`printf` and `time` formatting issues in a `zsh` shell script
I have the following (excerpt from a) zsh shell script (the FOLDER environment variable is exported earlier in the code):
# Create temporary directory
export TMPDIR=$(mktemp -d)
# Set TIMEFMT to ...
1
vote
1
answer
77
views
What's the difference in manipulating the array between echo and printf in Bash?
I'm surprised by the difference in manipulating the array between echo and printf in Bash:
printf cannot handle += operator
Both printf and echo cannot get results of += out of while loop
So, why?
I'...
2
votes
4
answers
996
views
printf as a bash builtin vs an executable (behavior differences)
I am trying to better understand printf so I read multiple pages on this command, but I also stumbled upon different behavior of %q directive. Namely, stated on this page:
What is the difference ...
0
votes
0
answers
34
views
How does printf() actually work? [duplicate]
When I execute the c file
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("before the system call. I am too excited!\n");
system("ps");
...
2
votes
0
answers
65
views
Rubbish value outputed by printf "%f" 380
The command
printf "%d, %f, %o, %s, %x, %X\n" 380 380 380 380 380 380
outputs
380, 20689...2384.000000, 574, 380, 17c, 17C
where the second output is a very large (with almost thousand ...
-1
votes
1
answer
126
views
Why is the printf Output Order Not Respected in a Concurrent Scenario with Piped or Redirected stdout?
We are in a concurrent scenario where we have n concurrent processes. By using a synchronization policy (e.g., using pipes or signals), each process can print using printf("string\n") only ...
-1
votes
3
answers
234
views
How to write script prefix braces with backslashes
I already posted add escape character with bash.
I need script to this for every line in a file that starts with {@codeBlock
so
{@codeBlock: TEstBigquerry.buildPicks}
should look like
\{@codeBlock:\ ...
0
votes
1
answer
67
views
Format output and columms
In Linux in Bash in a for loop i do:
... ; do echo "$i --> $i-new" ; ...
The output is than something like this:
file1 --> file1-new
file2 --> file2-new
...
file9 --> ...
-2
votes
2
answers
295
views
How to add string at a specific position in each line
With
awk '{ printf "%-15s %s\n", $1, $2 }' renamed | sort -V
... I get good output from the file renamed.
It looks like:
file1 file1.new
But I want to have the output changed to ...
0
votes
0
answers
43
views
printf seems to fail in bash [duplicate]
With version GNU bash, version 5.2.32(1)-release (x86_64-pc-linux-gnu) in present Debian testing this command:
$ printf '%010f\n' '1234'
000.000000
Doesn't use the number given and changes on every ...
7
votes
3
answers
415
views
Bash printf float formatting became nonsensical and random
Bash printf floating number formatting (with %f or %g) is suddenly completely wrong, and changing all the time.
An example output:
$ export LC_ALL=C
$ printf '%g\n' 1
1.20739e+3531
$ printf '%g\n' 1
4....
5
votes
1
answer
473
views
printf in Zsh does not shell escape exclamation mark
In Zsh 5.9, we can use printf to shell escape a string:
$ printf '%q' 'One! Two'
One\!\ Two
This produces the correct output of escaping the ! and the space. Now let’s make it as a script:
#!/bin/...
7
votes
1
answer
2k
views
printf - store formatted string output in a variable
Instead of the following
printf '%s\t%s\t%s\t%s\n' 'index' 'podcast' 'website' 'YouTube'
I want to store the printf output in a Results variable, how can I do this?
1
vote
1
answer
546
views
How do I pass hex characters to printf in a script command? [duplicate]
How do I get printf to output hex characters when run from a script?
Suppose I am at the prompt and type printf "\x41\x42" the output I get
AB%
However if I have a script containing that ...
2
votes
1
answer
315
views
Why does printing an array with @ using printf in bash only print the first element?
I have an array
snapshots=(1 2 3 4)
When I run
printf "${snapshots[*]}\n"
It prints as expected
1 2 3 4
But when I run
printf "${snapshots[@]}\n"
It just prints
1
without a ...