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++...)
290 questions
0votes
0answers
29views
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"); ...
1vote
0answers
54views
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 ...
-1votes
1answer
78views
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 ...
-1votes
3answers
139views
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:\ ...
0votes
1answer
43views
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 --> ...
-2votes
2answers
192views
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 ...
0votes
0answers
43views
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 ...
7votes
3answers
335views
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....
5votes
1answer
360views
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/...
7votes
1answer
1kviews
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?
0votes
1answer
249views
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 ...
2votes
1answer
259views
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 ...
0votes
1answer
651views
List all files in a directory, recursively, sorted by modification date
The main answer of Sort the files in the directory recursively based on last modified date gives a method to list all files in a directory, recursively, sorted by modification date: find -printf "...
1vote
1answer
26views
How to preserve updating output in pipe, e.g. when output has `\r`
Whenever I pipe some output that is updating (say with \r), e.g. to a pager (less), or to colourise parts of it, the pipe seems to drop the lines that are updating. Any idea how to preserve the ...
2votes
1answer
165views
Print Variable containing backslashes
I have something like this: A=$(curl https://mysite.com) and the curl request returns the string \"Hello World\". When I now want to print A to the console using one of: echo "$A" ...