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 UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 11-26-2007
Cameron's Avatar
Cameron Cameron is offline
Registered User
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 490
Vijay,

A crude solution is outlined below - Note - I highly suspect that this is not the most efficient way to perform this task.

ALSO!! Please, in future provide the forum with detail of your query and a sample of your code to show how far you have troubled. You'll likely get more qualified responses in return.

Contents of 'thefile.txt':
####<Nov12 2007> <user: Vijay> <user id:123456 college:anna univ> <error code: runtime exception>
####<Nov13 2008> <user: Cameron> <user id:789012 college:bond univ> <error code: tux runtime exception>


Script:
Code:
#!/bin/ksh

while read inline
do
  echo ${inline}
  detail=`echo ${inline} | cut -f 1 -d ">" | cut -f 2 -d "<"`
  user=`echo ${inline} | cut -f 4 -d " " | cut -f 1 -d ">"`
  uid=`echo ${inline} | cut -f 3 -d ">" | cut -f 2 -d ":" | cut -f 1 -d " "`
  uni=`echo ${inline} | cut -f 3 -d ">" | cut -f 3 -d ":"`
  err=`echo ${inline} | cut -f 4 -d ">" | cut -f 2 -d ":" | cut -f 2- -d " "`

  echo '- - - - - - - - - - - - - - - - - - - - - - - - - -'
  echo ''
  echo ' Detail:      '${detail}
  echo ' User:        '${user}
  echo ' User ID:     '${uid}
  echo ' University:  '${uni}
  echo ' Error:       '${err}
  echo ''
  echo '- - - - - - - - - - - - - - - - - - - - - - - - - -'
  echo ''

done < /home/cameron/thefile.txt
Output:
Code:
####<Nov12 2007> <user: Vijay> <user id:123456 college:anna univ> <error code: runtime exception>
- - - - - - - - - - - - - - - - - - - - - - - - - -

 Detail:      Nov12 2007
 User:        Vijay
 User ID:     123456
 University:  anna univ
 Error:       runtime exception

- - - - - - - - - - - - - - - - - - - - - - - - - -

####<Nov13 2008> <user: Cameron> <user id:789012 college:bond univ> <error code: tux runtime exception>
- - - - - - - - - - - - - - - - - - - - - - - - - -

 Detail:      Nov13 2008
 User:        Cameron
 User ID:     789012
 University:  bond univ
 Error:       tux runtime exception

- - - - - - - - - - - - - - - - - - - - - - - - - -
Reply With Quote