Picking a character from a word

Dennis G. Rears FSAC drears at ardec.arpa
Sun Apr 24 03:26:54 AEST 1988


Barsam Marasli  writes:

->I have a csh question.
->I would like to have a script that will echo, say the 4th character
->of an arguement. I came up with the following:
->
->set word=`echo $1 | od -c` ; echo $word[5]
->
->which seems to do the job but somehow I feel like there are
->more elegant ways of doing this. Please reply by e-mail or
->post. Also what's an alternative in sh? Thanx.
->
    If all you want is the fourth character of a word echod out try:

echo $1|cut -c4

This works in both the csh and the bourne shell.

...dennis
--------------------------------------------------------------------------
ARPA:	drears at ardec-ac4.arpa	UUCP:  	...!uunet!ardec-ac4.arpa!drears
AT&T:	201-724-6639		Snailmail:	Box 210, Wharton, NJ 07885
Flames:	/dev/null		Reincarnation: newton!babbage!patton!drears
Work:	SMCAR-FSS-E, Dennis Rears, Bldg 94, Picatinny Ars, NJ 07806
--------------------------------------------------------------------------



More information about the Comp.unix.questions mailing list