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

Filter by
Sorted by
Tagged with
2
votes
1answer
42 views

bash array printf in gnu parallel

I am trying pass bash array variable, that contain two elements to GNU parallel script: echo ${opts[@]} ...
0
votes
2answers
79 views

Bash printf formating not working

For example, the \c format does not work. I'm input printf "ABC\ctest" to bash console and result; ABC\ctest Considering the \c format's property, the expected output should be in the form of just ...
0
votes
0answers
21 views

Linux: print disappears for an executable in rc.local

I have an executable program /home/user/foo with root and executable permissions. The foo has 3 threads and performs outputs using printf. This program is placed in embedded target with Linux, 4.1.22-...
6
votes
3answers
238 views

BASH print question (printf \\$(printf '%03o' $1))

I used the following to convert from int to char and char to int in bash. But I do not understand how printf \\$(printf '%03o' $1) or printf '%d' "'$1" work. Please explain how printf \\$(printf '%...
0
votes
1answer
20 views

Multiline Variable add a Tab before each Newline

The Following snippet uses a custom function HexNewLine which basically converts the hexdump and breaks at the character 0x0a $ echo -e "\t{ > "dependencies": { > "prettier": { > ...
0
votes
2answers
24 views

Create multiples files with brace expansion combining letters and numbers

I am trying to create a series of files with brace expansions. I want create the files fileA1 to fileZ100 with all possible combinations (Something like touch file[A..Z][1..100]). If I run the ...
0
votes
3answers
19 views

Generate tex file containing all filenames in a directory

I have a folder containing 95 tex files. I need to create a tex file all.tex that contains the following code: \documentclass[10pt]{article} \begin{document} \input{file1.tex} \input{file2.tex} ... \...
0
votes
2answers
59 views

How can I pipe sed output to printf for formating?

I am using Tecplot to process wind tunnel data, but the input for Tecplot requires a specific format for variable specification; each variable is bracketed by double quotes "Variable Name". The ...
0
votes
1answer
66 views

How to print output to look like stairs?

My code is this in my shell script file: for i in {0..3} do COLOR_Value="\033[1;3"$i"m \t Hello World" echo -e $COLOR_Value done The output is this: (Each Hello World changes color as it ...
0
votes
2answers
36 views

delete numbers from a column consisting characters and numbers in bash

I have the following input file H1 C1 C2 C3 H2 C4 . . . I would like to obtain the following output format only with the characters and not the numbers H C C C H C . . .
0
votes
3answers
68 views

How to print the exact result of a command to a file

Context I have a file my-cmd: echo '<some data...>\\<some other data...>' Basically, I want to redirect the output of this command to a text file: ./my-cmd > file.txt Question My ...
3
votes
1answer
51 views

based on a line character, print corresponding number next to it

I have the following input format, H O C H H C H H O C H H C I would like to obtain the following output, H1 O1 C1 H2 H3 C2 H4 H5 O2 C3 H6 H7 C4
10
votes
4answers
290 views

Modify width of first column in file with a variable number of fields, using awk

I understand how to use awk's printf function, but I don't want to specify every field. For example, assume this is my file: c1|c2|c3|c4|c5 c6|c7|c8|c9|c10 c11|c12|c13|c14|c15 I want to format it ...
0
votes
0answers
93 views

How can I prepend the value of a variable to a column in bash? [duplicate]

I have a script that outputs a column of text. I want to prepend each entry in the column with a string stored as a variable. How can I do this? For example, consider the command $ echo -e "john\...
1
vote
1answer
82 views

Can you explain this inner working of this printf command in bash?

I stumbled onto the question Replacing only specific variables with envsubst and in one of the comments was this shell example: envsubst "$(printf '${%s} ' ${!PREFIX*})" < infile See the original ...
16
votes
2answers
2k views

Why won't some unicode characters print to my terminal?

I'm running Arch Linux with simple terminal using the Adobe Source Code Pro font. My locale is correctly set to LANG=en_US.UTF-8. I want to print Unicode characters representing playing cards to my ...
0
votes
3answers
78 views

multiply specific column in a file which consists of thousands columns

The in file looks like this -17.3644 0.00000000 0.00000000 .... -17.2703 0.00000000 0.00000000 .... -17.1761 0.00000000 0.00000000 .... -16.5173 0.00000000 0....
0
votes
0answers
23 views

How printf handles empty lines [duplicate]

Starting from: $ cat bib/10.2307_2983885.txt @article{10.2307/2983885, ISSN = {00359246}, URL = {http://www.jstor.org/stable/2983885}, abstract = {The essence of many statistical problems, ...
1
vote
1answer
28 views

how to print hyphen in double quotes along with other strings

cat inv_summary_1.txt | while read -r aLine do F1=`echo "$aLine" | cut -d "," -f1` F2=`echo "$aLine" | cut -d "," -f2` echo " 0 RUN_ID STR [0] \"${F2}\" " done 191245204696,REG-...
0
votes
3answers
46 views

print out the sequence r1 r2 … r100 in column

I would like to have the following output r 1 r 2 r 3 . . . r 100 I have tried so far printf "%s\n" "r {1..100..1}"
1
vote
1answer
43 views

what is the meaning of %< in printf statement? [duplicate]

i get </ttd> instead of </td> in the below printf. Can someone please explain why. i want % symbol in my output. But it adds extrac t in my output. awk '{printf("<td>%0.2f`%</td&...
0
votes
1answer
100 views

How to properly write a string to a named pipe and the difference between echo and printf

Problem: I need to send a command to a named pipe and need to ensure only the command is sent and not any errant or "fat-fingered" characters. Example: I have been using the following: echo "...
3
votes
2answers
207 views

Add leading zeroes to a user's input but is being transformed with printf

I am currently looking for an alternative to the following code that works a little less 'wonky'. printf "Please enter the ticket number:\t"; read vTICKET; vTICKET=$(printf %04d "$vTICKET"); printf "$...
2
votes
3answers
260 views

How to reverse input order?

The following code provides a backwards output when inputted as first to last, so input is required to be in reverse. How can this be flipped/reversed? EDITED on 2019-05-23_07:52:04 (printf 'g?%s?m0\...
3
votes
1answer
47 views

Can the output of find with the -printf flag be colorized?

The command find . -type l -not -xtype l -printf "%p -> %l\n" prints all nonbroken symlinks under the directory .. I want to colorize this output so that the %p part is blue. I've tried find . ...
0
votes
1answer
81 views

How to modify this `printf` code to accept input in first to last order, or flip output?

Code below can, for example ... [anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt ... take all of numbers within ... [anony@mous-pc ~]$ cat file.txt 005 003 ...
0
votes
2answers
90 views

How to modify this `printf` code to reverse it's action?

Code below can, for example ... [anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt ... take all of numbers within ... [anony@mous-pc ~]$ cat some.txt 005 003 ...
6
votes
3answers
502 views

Shell builtin `printf` line limit?

The /usr/bin/printf util argument list length is limited to the shell's maximum command line length, (i.e. getconf ARG_MAX, on my system that'd be 2097152); example: # try using a list that's way too ...
2
votes
1answer
292 views

How to modify this `while read; mv printf` code to rename only files of certain filetype?

Code in question: ls | cat -n | while read n f; do mv "$f" `printf "video_%03d.mp4" $n`; done The above code will rename all files/folders within the directory executed to: video_001.mp4 video_002....
1
vote
2answers
49 views

print a sequence in a file

I would like to print in a column in a new file the following 1_number_density_per_atom_1.xvg 1_number_density_per_atom_2.xvg 1_number_density_per_atom_3.xvg . . . 1_number_density_per_atom_653.xvg ...
4
votes
3answers
5k views

Using `printf` to print variable containing `%` percent sign results in “bash: printf: `p': invalid format character”

I want to use printf to print a variable. It might be possible that this variable contains a % percent sign. Minimal example: $ TEST="contains % percent" $ echo "${TEST}" contains % percent $ printf ...
1
vote
3answers
49 views

read file and based on criterion print desire output

I have input file which looks like this: H1 O1 C1 H2 H3 O2 C2 Br1 I want to have an output file which to have the following output H1 = 1 O1 = 8 C1 = 6 H2 = 1 H3 = 1 O2 = 8 C2 = 6 Br1 = 35 So when ...
2
votes
1answer
59 views

Newline character produced by `echo`, is it always there when using no options, regardless of shell?

Although I have read Stephane's answer concentrated on basically all aspects of echo vs printf, I am unsure if it also answers my question, which stands: The newline character produced by echo, is it ...
0
votes
2answers
254 views

Using printf with escape sequences?

I can change my cursor shape like this: printf "\x1b[\x31 q" # block :) printf "\x1b[\x35 q" # ibeam :) But when I assign that to a variable with %s and expand using printf, it doesn't work: CURSOR=...
0
votes
1answer
111 views

printf and echo -e are giving different results

I am using \0n escape sequence with echo -e and printf where n is the octal value of the ASCII character to be printed. When i used the statement echo -e "\0101" the shell is printing character A but ...
0
votes
1answer
96 views

printf outputs rows, not columns

I have two arrays, which I want to print out in two separate columns from a single printf call. The following: printf "%-${padding}s→ %s\n" "${lnFrom[@]}" "${lnTo[@]}" Outputs: dotfiles/git/...
13
votes
6answers
1k views

Only print output after finding pattern

There's a script (let's call it echoer) that prints to screen a bunch of information. I'd like to be able to only see lines after a pattern is found. I imagine the usage of a solution to look ...
0
votes
2answers
73 views

Writing to a file horizontally

I have a script that I want to run and then write the output to a file in a specific format Currently when I run the script and direct it to standard output it gives it to me in the format I want. The ...
0
votes
1answer
40 views

Printf format error for number

After some greping and seding I manage to get a value from a csv cell and assign it to a variable (DBR). Here come some odd findings echo $DBR echo "$DBR", printf "%f" $DBR output: 9.1 ,.1 : ...
5
votes
1answer
67 views

%c formatted string shows different behaviour in the shell and in C

If i write a very simple line of code in C: printf("Ascii char for %d is %c\n",65,65); It simply prints A, as ascii value of 65 corresponds to character A. But if I use the same code in shell and ...
14
votes
3answers
726 views

Slightly confused about whether printf in the yash shell is a built-in command or not

The yash shell has a printf built-in, according to its manual. However, this is what I see in a yash shell with default configuration: kk@eeyore ~ $ command -v printf /usr/bin/printf kk@eeyore ~ $ ...
0
votes
1answer
195 views

Find + -printf + sort conflict?

I need to pass a list of sorted, quoted FLAC file names to SoX for concatenation but am having trouble getting sort to work the way I expect it to. If I use: find . -maxdepth 1 -type f -iname "*....
0
votes
0answers
29 views

Filter output / print one record per event or time period

I've got a custom HID device which prints out exact coordinates of touched points at real time. It is very sensitive & currently printing out the coordinate that's being touched on multiple ...
3
votes
2answers
1k views

What characters need to be escaped when using the printf command?

I want to clarify that I am not talking about how to escape characters on the shell level of interpretation. As far as I can tell, only two character need to be escaped: % and \ To print a literal %,...
8
votes
2answers
627 views

Explanation needed on how I can repeat a character in POSIX shell

The following answer on Stack Overflow, How can I repeat a character in bash? imposes one plausible way of POSIX-ly repeating a single character, as follows. In this example let's use the equal sign ...
1
vote
1answer
295 views

Printf - print repeating minus symbols [duplicate]

how can I use printf to print a row of minus symbols? when I try: printf "-----------\\n" I get: bash: printf: - : invalid option printf: usage: printf [-v var] format [arguments] when I try: ...
1
vote
3answers
186 views

print a column with the desire format output [closed]

I have a list of the following data in a file: -0.3476890000000000 0.0743938333333333 -1.0990240000000000 0.0743938333333333 -0.2169100000000000 0.0879397500000000 and I am ...
0
votes
2answers
58 views

how to alignment the output of the last fields

the bash script for i in $script_name do echo -en "running the script - $i\t - " exec 3>&1 4>&2 var=$( { time /tmp/scripts/$i 1>&3 2>&4; } 2>&1) # Captures ...
10
votes
2answers
2k views

Why does `printf “%s”` concatenate two following strings together? [duplicate]

$ printf "%s" a b ab$ printf "%s%s" a b ab I have some problem understand the format specifier for printf. If I am correct it is mostly the same as those for strings in the C programming language. ...
1
vote
2answers
45 views

Printing a file in columns with arbitrary amount of rows

I have this file: line1 line2 line3 line4 line5 line6 line7 line8 line9 And I want to print it across 3 columns with this structure so that first column has lines 1-2-3, second column has the lines ...