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
.