Picking a character from a word

Kenneth Kutz kutz at bgsuvax.UUCP
Mon Apr 25 11:17:46 AEST 1988


In article <578 at amethyst.ma.arizona.edu>, barsam at eros.ame.arizona.edu (Barsam Marasli) writes:
> 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.

Use 'cut' if you have it.

[echo "stuff" | cut -c3] --> outputs 'u'
         
similarly

[echo "stuff" | cut -c1] --> outputs 's'


-- 
--------------------------------------------------------------------
      Kenneth J. Kutz         	CSNET kutz at bgsu.edu
				UUCP  ...!osu-cis!bgsuvax!kutz
 Disclaimer: Opinions expressed are my own and not of my employer's
--------------------------------------------------------------------



More information about the Comp.unix.questions mailing list