Re: How to insert header and trailer in txt file using shell script



On 16 Aug 2006 23:17:30 -0700, bonnie.tangyn@xxxxxxxxx wrote:
I used printf "%s\n" $(($wc -l < "$f.bak") + 2)) to append total number
of rows in $f.bak and header and trailer at the end of the text file.
How can I put spaces in front of the outputed total number of rows?

For example:
output result: 504
it will put: ^^^^^^504 where ^ is space

output result: 2
it will put ^^^^^^^^2

How can I put space in front of the no. of rows automatically?
[...]

printf 'output result: %9d\n' "$number"

Or in awk:

printf "output result: %9d\n", number

$ printf '%9d\n' 1 11 111 1111
1
11
111
1111


You can use %9s instead if you want.

Differences are only about:

$ printf '%9s\n' 01
01
$ printf '%9d\n' 01
1
$ printf '%9d\n' 0x20
32

--
Stephane
.



Relevant Pages

  • Re: definition of stdio.h
    ... define printf and scanf in a header (though it must also be fully ... Only an idiot or a completely macro-crazed bozo would define printf and ...
    (comp.lang.c)
  • Re: Portable printf specifier
    ... > For printf, int uses %d, long uses %ld. ... The C99 approach is to add a second header,, that defines ... macros for *printfand *scanfconversion specifiers for these ...
    (comp.lang.c.moderated)
  • Re: Micro-C -- Help monitoring a switch on 8051
    ... Since printf() doesn't ... >and most likely has a header you should include if you use it. ... Low cost software development tools for embedded systems ...
    (comp.lang.c)
  • Re: definition of stdio.h
    ... define printf and scanf in a header (though it must also be fully ... Only an idiot or a completely macro-crazed bozo would define printf and ...
    (comp.lang.c)
  • Re: ES format
    ... (snip regarding run time format and C's printf) ... > like printf() specially provided that the appropriate header is ... It might be that it is reserved, even without the header. ... There was the Fortran question relating to external functions ...
    (comp.lang.fortran)