The UNIX and Linux Forums  

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 -->
  #2 (permalink)  
Old 03-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink One approach to try...

From what info you provided, this is one approach.

Quote:
> cat sample
define host{

host_name hostA
parents hostNull
}
--
define host{

host_name hostB
parents hostA
}
--
define host{

host_name hostC
parents hostB
}

Code:
> cat bld_csv 
#! /bin/bash

echo "host,parent" >host.csv
while read zf
  do
  hck=$(echo "$zf" | cut -d" " -f1)
  if [ "$hck" = "host_name" ]
    then
    hnm=$(echo "$zf" | cut -d" " -f2)           
  fi
  if [ "$hck" = "parents" ]
    then
    pnm=$(echo "$zf" | cut -d" " -f2)
    echo $hnm","$pnm >>host.csv
  fi

done < sample

Quote:
> cat host.csv
host,parent
hostA,hostNull
hostB,hostA
hostC,hostB