The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
2answers
41 views

How to printf an exclamation point in tcsh?

What's the best way to printf an exclamation point in tcsh? It seems like using single or double quotes has no effect on escaping the exclamation point; and using a backspace does work, but then it ...
4
votes
3answers
138 views

How do I capture stdin to a variable without stripping any trailing newlines?

In a shell script... How do I capture stdin to a variable without stripping any trailing newlines? Right now I have tried: var=`cat` var=`tee` var=$(tee) In all cases $var will not have the ...
1
vote
3answers
60 views

Using a command's output in printf in ksh

I am trying to perform the following : printf "Are you sure you want to copy %s (y/n) ? (file bigger than 10 MB) " "$0" It works fine, nevertheless, I would like to display the actual size of my ...
4
votes
5answers
225 views

Add leading characters infront of string using printf or echo

How can I add leading characters to fill a string to a certain length? Assume I want to add zeroes infront of a string, if said string is shorter than 20 characters: printf '%020s\n' "$line" ...
3
votes
2answers
269 views

Thousands separator in printf in zsh

I have been trying to define a thousands separator in printf for a while now and I have discovered that zsh has some problems with it. In bash I can use something like: $ printf "%'d\n" 1234567890 ...
0
votes
2answers
1k views

Awk printf number in width and round it up

I need to printf a number out, but with given width and rounded (with awk!) %10s I have this and somehow I need to connect the %d but everything I do, ends up with too much parametres for awk ...
2
votes
2answers
190 views

printf output running over into next line

I have created Bash SS in vi. My output is running over into the line below it. I am new to UNIX so I'm trying to learn. My output is displayed using printf. printf "%-15s %15s %15s %2d\n %2s " ...
4
votes
1answer
175 views

One liner for padding columns (similar to printf) of output from the previous pipe command?

I'd normally use printf to pad each cell with enough whitespace to maintain header position over its respective column. Ultimately I can just iterate over each line of the output and do enough cut ...
3
votes
0answers
187 views

How to create a bash command which creates output that exactly mimics a source text file that can be pasted into bash shell where histexpand is on?

The goal is to create a bash one line command that can be copied and pasted - for instance published on a web forum - and then patches files. See it as a way to distribute a patch file by copy and ...
3
votes
2answers
548 views

Why does Bash history not record this command?

The command printf "#!/bin/bash\n" > t generates an error(bash: !/bin/bash\n": event not found), but hitting the up key does not recall the command so that I can modify it. Why is that? (What I ...
1
vote
1answer
101 views

How to compute a thumbnail filename from the shell?

I started noticing some time ago in Xfce4 that when I sent some file to the Trash, tumbler (the Xfce4 thumbnailer) would cause very high I/O load for quite some time. Upon investigating the issue, I ...
1
vote
3answers
113 views

How to print to the left and right of already printed output

I have a command say printf "%5s1" and its output is: 1 How can I print digit 2 to left and digit 3 to right of already printed 1. So, the output looks like below: 213 So, there is one ...
3
votes
2answers
859 views

Overwriting line in unix shell after printing

How can I modify a line after printing it in unix shell.We can delete the line and write again by using \r as shown below,but how can I overwrite on existing line and not delete it completely and get ...
3
votes
4answers
1k views

Pad a number with a zero

I'm trying to pad zero to a number a=010 printf "%04d" $a 0008 I need the "output" as "0010" it's converting the value..can any one help on this ?? and even tried with typeset a=010 typeset -RZ2 ...
1
vote
1answer
2k views

i/o format with printf in bash-shell

I am trying to output the results of my shell script using printf. To keep the results aligned in column, I am using tab as: printf "%s\t %s\t %s\t %s\t %s\t %s\t %s\n" $i $est $var_m $jk $mst $var_M ...
2
votes
2answers
629 views

Where can I find some good documentation for bash printf?

man printf, info printf and printf --help are all pretty useless to me; I want an explanation of the FORMAT options. For example, I could use: printf '%s\n' foo bar and get output: foo bar From ...
3
votes
1answer
437 views

Setting the column position in printf

How to fix the positions of output string in shell using printf? For example ,if I want to print text TEXT-A at position starting from third position from left and one more text TEXT-B at eleventh ...
3
votes
1answer
103 views

Print arguments to printf in no particular order

How can I refer back to arguments to coreutil's printf in no particular order? This is what I want to avoid: $ printf '%s %s %s %s %s %s %s' a c a c b c a a c a c b c a This is what I would like ...
2
votes
1answer
811 views

bash script , echo output in box

I have created this Function , which generate below output on terminal , but this function seems complex, So I posted here for any improvement or for same alternate solution. #!/bin/bash function ...
151
votes
5answers
51k views

Why is printf better than echo?

I have heard that printf is better than echo and I can recall only one instance from my experience where I had to use printf because echo didn't work for feeding some text into some program on RHEL ...
1
vote
1answer
282 views

Why does printf ignore the IFS when printing out the result of my script?

This is a follow up to a question posted on SO. I've written a script called except which should print all filenames / directories except the ones given like so. $ ls a b c d $ rm $(except b d) $ ls ...
0
votes
1answer
335 views

Pretty print in VIM?

I have few lines that each of them are colon separated values, abc:def:3 Now I could do the reformat with printf plus IFS variable, while read line; do IFS=":" printf "%-20s %-16s %5d\n" ...
2
votes
3answers
7k views

print output to 3 separate columns

MYPATH=/var/www/html/error_logs/ TOTALFILE=$(ls $MYPATH* | wc -l) FILETIME=$(stat --format=%y $MYPATH* | head -5 | cut -d'.' -f1) FILE=$(ls -1tcr $MYPATH* | head -5 | rev | cut -d/ -f1 | rev) ...
0
votes
1answer
816 views

Where to find printf formatting reference?

Where is the offline reference of the format specifiers (e.g., %i, %s) which are supported by the Bash/system printf command? I've looked in help printf, man 1 printf and man 3 printf without luck. ...
4
votes
3answers
846 views

Prevent watch breaking colors

I'm altering scripts at work that monitor log files to single out certain items and colorize them. The final output is a list of 6-digit numbers in several columns. I've been able to add a ~ to the ...