The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: TO break a line
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 08-28-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
With zsh:


Code:
zsh 4.3.4 % host=(${$(grep -F Host file)//[^0-9.]/})
zsh 4.3.4 % print $host[1]
192.168.2.2
zsh 4.3.4 % print $host[2]
192.168.2.4

With bash:


Code:
bash 3.2.13(1) $ while read;do 
> [[ "$REPLY" == *Host* ]]&&host=($host ${REPLY//[^0-9.]/})
> done<file
bash 3.2.13(1) $ echo ${host[0]}
192.168.2.2
bash 3.2.13(1) $ echo ${host[1]}
192.168.2.4