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
3answers
68 views

Padding unicode strings with bash's printf

I tried padding a Unicode string with bash's printf, and saw that, while printf "%2s" a yields the expected " a", a Unicode variant printf "%2s" ä yields a ...
0
votes
0answers
34 views

Get the last modified file's epoch time in current directory

I need to get the epoch time which belongs last modified file in current directory. I have some limitations: must be compatible with RHEL and AIX systems AIX does not allow -printf option with find ...
2
votes
0answers
18 views

Bash Printf Argument $1 vs “$1” [duplicate]

I have a shell script that prints the first argument passed to it in the command line. I was experimenting with $1 and "$1". Interestingly to me, when I pass "John Doe" I get ...
-1
votes
1answer
36 views

what does this do? printf '\t%s\n' “$@”

I'm writing a larger bash script, and I've found this snippet to test if a directory exists case insensitive Now, if I now have one directory called subs this script will print the path, and if I have ...
0
votes
1answer
44 views

How to print variable value as a hex number?

I can find seemingly every variation of hex manipulation by printf except this one. I am trying to send html hex colour values to a text file, built mostly using printf. I can calculate the separate R,...
0
votes
1answer
38 views

Using awk Printf to print a full number

I'm using FSL (a neuroimaging programme) and I have a for loop to analyse all my participants. The line in question is : fslstats <FILENAME> -M -V | awk '{print $1 * $3 }' How do I get the awk ...
1
vote
1answer
55 views

why printf executes string instead of formatting

I'm newbie in bash scripting I want to format command with printf to prepare execution and assign into variable. But it is executing immediately. It is listing /opt/cinar/packages/libcnrhttp2_* ...
0
votes
1answer
39 views

List contents of a directory and all sub directories including file details, i.e. size, date created, date modified, and date last opened

First I should apologize in advance - I have no idea what I'm doing when it comes to the Mac terminal... I need to do an inventory of all files in a directory/folder. There are several sub ...
0
votes
2answers
46 views

set format with printf for $0

I compute the row average of the following data set however I have trouble setting the correct format for $0 so as to produce the file-output presented below. I currently have: awk '{T=0; for (i=1;i&...
0
votes
1answer
31 views

Locating printf object/module

I would like to know which kernel module is called when printf is executed in my C code. How can I find that? Let's say, when I use ldd I can find which libraries are attached to my binary file. I am ...
0
votes
2answers
40 views

Output Bash argument with multiple single quotes to file verbatim (without losing any single quotes)

I'm trying to: Accept input in bash and store it verbatim to a file cat the contents of the file. Any special characters should also be written verbatim to the file. Sample Input ./verbatim.sh -a ...
0
votes
3answers
67 views

Inserting text with formatting at the start of a file with printf

I need to append something with particular formatting at the start of a text file. I have looked into How do I append text to the beginning and end of multiple text files in Bash, but not sure how to ...
0
votes
3answers
65 views

bash counting script, counts fine ascending, doing error by counting descending

The follow bash script works fine for for high counting number ranges from 1..1000 By high counting number ranges, bigger than 1..1000000, it needs some time to start. In general, it's working fine. ...
0
votes
1answer
25 views

dash: echo args exactly with no processing

I want to do sth like zsh's print -r -- ... which just echoes the arguments without changing them at all. printf -- still interprets directives.
1
vote
3answers
57 views

How can I modify -printf “%s \n” in find command to give me size in MB and not bytes?

I am writing a simple helper function to show a sizes of the files: This is the code I have so far: find . -type f -size +10M -printf "%f -> %s B\n" The output I get is: clay-banks--Ni2fpLUgRI-...
3
votes
2answers
247 views

trying to use printf to decode unicode characters passed in as arguments

I am trying to printf some unicode codes that I pipe in like this echo 0024 0025 | xargs -n1 echo # one code per line | xargs printf '\u%s\n' hoping to get this $ % but this is what I get ...
0
votes
1answer
48 views

Output from the printf is different than specified in the FORMAT argument

I'm a little confused, the output from the printf is different than specified in the FORMAT argument: $ echo "$PWD_HASH" {SHA512-CRYPT}$6$ZLgRL2DZSKYUCzht$PaTcpkoOi6P6p9ItIjRTL00MCB/8IU.fJbGk9EO/...
0
votes
1answer
28 views

How to get multiple variables within a single neat column?

I want to display a list like this: | A | B | Item #1 | 291+4 | 56145+3 | Item #2 | 7391+92 | 105+6067 | but it looks like this: | A | B | ...
2
votes
1answer
45 views

String removal inside xargs printf statement?

Currently my mbsync is erroring out with a bunch of duplicated UIDs. This means I have to find all files that have duplicates of the sub-string "U=[0-9]+:" and change the most recent file to remove ...
0
votes
2answers
68 views

align text bash script

I'm writing a script that will check the many applications services. I have the script looping through the services. Just looking for the best way to align the output text. Here is the code: ...
3
votes
1answer
111 views

Why echo after printf is not displaying in a new line?

I have a code which will use printf and then echo command. As per my understanding echo will by default come in new line, but not happening when it is used after printf. Below is the code: #!/bin/...
2
votes
3answers
387 views

convert one line values to multiple lines with numbering order

The following variable include for example this values echo $SERVERS server1,server2,server3,server4,server5 and when I want to pipe them on different lines then I do the following echo $SERVERS | ...
6
votes
3answers
3k views

Why doesn't printf escape newlines?

$ printf "hi" hi$ printf "hi\n" hi $ printf "hi\\n" hi Why doesn't the last line print hi\n?
2
votes
1answer
103 views

bash array printf in gnu parallel

I am trying pass bash array variable, that contain two elements to GNU parallel script: echo ${opts[@]} ...
1
vote
2answers
235 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
23 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-...
7
votes
3answers
533 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
46 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
38 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 ...
1
vote
4answers
27 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
245 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
93 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
39 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
78 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
53 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
383 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
234 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
138 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
3k 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
165 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....
1
vote
1answer
33 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
50 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
51 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
326 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
290 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
371 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
72 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
92 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
119 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
663 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 ...

1
2 3 4 5