[Novalug] substrings FQDN names in bash scripting
Jon LaBadie
novalugml@jgcomp.com
Tue Mar 3 15:41:16 EST 2009
On Tue, Mar 03, 2009 at 07:41:27PM +0000, Miguel Gonzalez wrote:
>
> Dear all,
>
> It's driving me nuts...
>
> I'm trying to short a list of servers which comprises short and FQDN server so all of them are converted to hostnames so if i have:
>
> server1.domain.com
> server2
> server3.domain.com
>
> I convert them all into:
>
> server1
> server2
> server3
>
> I have a $i variable that iterates the list of servers.
>
> I was trying something like:
>
> echo ${"$i":echo `expr match "Si" '.*'`}
>
> but it doesn't work.
Forgot to add, if you want to do this with shell parameter
substitution you could try:
echo ${i/.*/}
echo ${i%%.*}
and if you must use expr try:
expr match "$i" '\([^.]*\).*'
--
Jon H. LaBadie jon@jgcomp.com
JG Computing
12027 Creekbend Drive (703) 787-0884
Reston, VA 20194 (703) 787-0922 (fax)
More information about the Novalug
mailing list