Counting characters in a string...bourne

Dave Taylor {guest} dt at mathcs.emory.edu
Wed Oct 10 02:55:55 AEST 1990


First off:

I am trying to count the number of characters in a string, but I seem to
be running into problems.  I tried:
	echo $STRING | wc | awk '{ print $3 }'
the only problem with this is that it drops spaces.  I want to count ALL
the characters.  I suppose I could just adapt some of the awk scripts that
have been flying on the newsgroups lately, but I was looking for something
clean and simple.

Secondly:

WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY ??

Why does the following string get pushed together??

Script:
TITLE="This              is some text"
echo "$TITLE"

Output:
This is some text

How to I keep it from being pushed together??


THIRDLY:

The point of all this is to be able to center a header with pwd in it.  So that
is says something like:

program 1.1			Check to see foo.bar			/u/user

I need to count the spaces between bar and EOL as well as the length of the pwd
string.  A while loop using expr to count takes an eternity.  What could make
it faster???

Thanks in advance,


--david
-- 
-------                                                                 -------
David E. Taylor, OMSS UNIX Development // Operation Mobilization USA
AT&T: (404) 631-0432  +====+  UUCP:    {decvax, sun!sunatl, gatech}!emory!om!dt
FAX:  (404) 631-0439  +====+  Internet: dt%om.uucp at mathcs.emory.edu



More information about the Comp.unix.shell mailing list