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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parsing output from SQL querry ludvig Shell Programming and Scripting 7 10-23-2007 05:42 AM
Problem with parsing a large file gauravgoel Shell Programming and Scripting 6 10-18-2006 05:48 PM
Problem parsing line in file rlwilli Shell Programming and Scripting 2 09-02-2006 11:15 AM
problem parsing process-output victorin Shell Programming and Scripting 3 07-25-2006 05:31 AM
parsing output from ls command ajaya Shell Programming and Scripting 3 05-10-2006 10:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2007
ragha81 ragha81 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 145
problem parsing output file

Hi Gurus,

I am using the following code to parse the output of a file. This code basically parses the file and adds | at the end of each field. But I am getting it wrong in some cases. I have explained it below
Code:
#----- parse output file, get each field position, -----
#----- and construct command string                -----
LINE=`cat $temp_output_tasks | grep "\-\-"`
count=1
PreCHR="-"

while [ 1 ]
do
    CHR=`echo "$LINE" | cut -c$count`
    if [[ -z $CHR ]]
    then
      break
    fi

    if [ "$CHR" != "$PreCHR" ]
    then
      if [ "$CHR" != "-" ]
      then
        #--Find the end point of the field, write it to command--
        pos=$count
        (( pos -= 1 ))
        command=$command" | perl -pe'substr(\$_,$pos,1)=\"|\";'"
      fi
    fi
    PreCHR=$CHR
    (( count += 1 ))
done
#----- Now we have the positon of each field, run the command, ----
#----- and add "|" at the end of each field                    ----

command="grep ^sblp $temp_output_tasks"$command
eval $command > $outputs

#----- Remove white space ----
sed 's/ \{1,\}\|/\|/g' < $outputs > $temp_output_tasks
sed 's/|\ \{1,\}/\|/g' < $temp_output_tasks > $outputs
The file that needs to be parsed looks like this

Code:
Siebel Enterprise Applications Siebel Server Manager, Version 7.8.2.3 [19221] LANG_INDEPENDENT 
Copyright (c) 2001 Siebel Systems, Inc.  All rights reserved.

This software is the property of Siebel Systems, Inc., 2207 Bridgepointe Parkway,
San Mateo, CA 94404.

User agrees that any use of this software is governed by: (1) the applicable
user limitations and other terms and conditions of the license agreement which
has been entered into with Siebel Systems or its authorized distributors; and
(2) the proprietary and restricted rights notices included in this software.

WARNING: THIS COMPUTER PROGRAM IS PROTECTED BY U.S. AND INTERNATIONAL LAW.
UNAUTHORIZED REPRODUCTION, DISTRIBUTION OR USE OF THIS PROGRAM, OR ANY PORTION
OF IT, MAY RESULT IN SEVERE CIVIL AND CRIMINAL PENALTIES, AND WILL BE
PROSECUTED TO THE MAXIMUM EXTENT POSSIBLE UNDER THE LAW.

If you have received this software in error, please notify Siebel Systems
immediately at (650) 295-5000.

Type "help" for list of commands, "help <topic>" for detailed help

Connected to 48 server(s) out of a total of 54 server(s) in the enterprise

srvrmgr> list tasks show SV_NAME TK_PID TK_START_TIME TK_PID TK_DISP_RUNSTATE TK_PID TK_END_TIME TK_PID TK_TASKID TK_PID TK_LABEL TK_PID TK_PID TK_PID CC_ALIAS

SV_NAME  TK_START_TIME        TK_DISP_RUNSTATE  TK_END_TIME          TK_TASKID  TK_LABEL       TK_PID  CC_ALIAS                
-------  -------------------  ----------------  -------------------  ---------  -------------  ------  ----------------------  
sblp001  2007-03-19 17:28:45  Completed         2007-03-19 17:28:45  152473                            eCommunicationsObjMgr_enu
but I get this as output whenever there is @ character in one of the fields

Code:
sblp001|2007-03-19 17:20:49|Running||151115|anderst22@bp.|om  258|6   eCustomerCMEObjMgr_|nu
This should actually read like below
Code:
sblp001|2007-03-19 17:20:49|Running||151115|anderst22@bp.com |2586|  eCustomerCMEObjMgr_enu
Please help oyt guys. thanks in advance
  #2 (permalink)  
Old 03-19-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Code:
#!/usr/bin/ksh

PATTERN=`grep "^--" <file> | sed -e "s/-  -/-\\\\\)  \\\\\(-/g" -e "s/^/\\\\\(/" -e "s/$/\\\\\)/" -e "s/-/\./g"`
grep "^sbl" <file> | sed -e "s/${PATTERN}/\1|\2|\3|\4|\5|\6|\7|\8/" -e "s/[ ]*|[ ]*/|/g"
  #3 (permalink)  
Old 03-19-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Independant of number of columns and number of spaces between columns:

Code:
#!/usr/bin/ksh

PATTERN1=`grep "^--" test | sed -e "s/-[ ][ ]*-/-\\\\\)[ ][ ]*\\\\\(-/g" -e "s/^/\\\\\(/" -e "s/$/\\\\\)/" -e "s/-/\./g"`

typeset -i FIELDS=`grep "^--" test | wc -w`

COUNT=1
while [ ${COUNT} -le ${FIELDS} ]
do
  PATTERN2="${PATTERN2}|\\${COUNT}"
  ((COUNT=${COUNT}+1))
done

PATTERN2=`echo "${PATTERN2}" | sed -e "s/^|//"`

grep "^sbl" test | sed -e "s/${PATTERN1}/${PATTERN2}/" -e "s/[ ]*|[ ]*/|/g"
  #4 (permalink)  
Old 03-19-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Ooooooooooops

Problem is caused because

-------------
anderst22@bp.com

The value is more charecters then the number of dashes "-" indicating the field length
  #5 (permalink)  
Old 03-20-2007
ragha81 ragha81 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 145
how do I correct that problem.. please suggest some modifications to the code for me to correct the issue.. its really urgent
  #6 (permalink)  
Old 03-20-2007
ragha81 ragha81 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 145
hi sbp008

thanks a lot for your reply..

your code is working exactly as expected. however i have one more question, i want to store the output of your grep into another file. how do i do that. please help me out with that.

thanks in advance.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0