Skip to main content

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++...)

0 votes
0 answers
29 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"); ...
KeShAw's user avatar
  • 13
1 vote
0 answers
54 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 ...
KeShAw's user avatar
  • 13
-1 votes
1 answer
77 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 ...
Spartacus's user avatar
-1 votes
3 answers
139 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:\ ...
MikiBelavista's user avatar
0 votes
1 answer
43 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 --> ...
user447274's user avatar
-2 votes
2 answers
190 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 ...
user447274's user avatar
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 ...
smf's user avatar
  • 1
7 votes
3 answers
333 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....
PlasmaBinturong's user avatar
5 votes
1 answer
357 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/...
user137369's user avatar
7 votes
1 answer
1k 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?
Porcupine's user avatar
  • 2,146
0 votes
1 answer
244 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 ...
sgmoore's user avatar
  • 125
2 votes
1 answer
258 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 ...
geckels1's user avatar
  • 173
0 votes
1 answer
645 views

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 "...
Basj's user avatar
  • 2,651
1 vote
1 answer
26 views

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 ...
suvayu's user avatar
  • 162
2 votes
1 answer
165 views

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" ...
Cake's user avatar
  • 31

15 30 50 per page
1
2 3 4 5
20