Michael C. Toren on Sat, 11 Dec 1999 14:43:31 -0500 (EST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [Plug] String Conversion


> I'm trying to create a shell script and I've run into a stumbling block in 
> terms of converting one string into another. cut and tr don't seem to be 
> able to do what I want. An example of what I want to do is if you had the 
> string "foobar" and you wanted to convert every instance of "oba" to "josh", 
> but you didn't want to convert the other o to anything. So the desired 
> result would be "fojoshr"

If you're using a version of bash later than 2.0 (I believe), you can do
something along the lines of:

	i=foobar
	echo ${i/oba/josh}

Or, from other more traditional shells:

	i=foobar
	echo $i | sed -e s/oba/josh/

-mct