The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #8 (permalink)  
Old 12-04-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
@samshaw:

Perhaps you should open your own thread?

For a start try this:

Code:
HOSTS=( $(sed -n 's/^<hostAddress>\([^<]*\).*/\1/p' xfile) )
It will write the results of the sed command into an array HOSTS.

Code:
echo ${HOSTS[1]} etc.
Will give you the values.

Sed is best learned by example. There are many pages with sed one liners.
This one here does the following:

-n only print if asked to print a line
's/ substitute
^<host every line starting with host
\([^<]*\) every character except a "<" and save what you have found in "\1"
.* the rest of the line
/\1/ substitute by what we have just save in \1
p' print this line.

The command does two tasks at a time: a) it finds all lines starting with
host..., b) it extracts the value between the tags.

HTH Chris