Getting at the first char of a string in Bourne shell
Larry Wall
lwall at jpl-devvax.JPL.NASA.GOV
Sat Sep 29 09:59:11 AEST 1990
In article <1308 at ncrwat.Waterloo.NCR.COM> ken at images1.Waterloo.NCR.COM (Ken Braithwaite) writes:
: I am trying to peel off one at a time the letters from a variable
: in the Bourne shell, ie from Bourne get B and ourne.
: How can I do this?
A fairly efficient way would be
echo "Bourne" | SOMETHING | while read line; do
...
done
where SOMETHING is one of
sed 's/\(.\)/\1\
/g
s/\n$//'
perl -pe 'chop; s/./$&\n/g'
There are lots of other ways.
Larry Wall
lwall at jpl-devvax.jpl.nasa.gov
More information about the Comp.unix.shell
mailing list