problem parsing output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem parsing output file
# 1  
Old 03-19-2007
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  
Old 03-19-2007
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  
Old 03-19-2007
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  
Old 03-19-2007
Ooooooooooops

Problem is caused because

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

The value is more charecters then the number of dashes "-" indicating the field length
# 5  
Old 03-20-2007
how do I correct that problem.. please suggest some modifications to the code for me to correct the issue.. its really urgent
# 6  
Old 03-20-2007
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.
# 7  
Old 03-20-2007
Hii. Your code is giving me issues as well. I am getting output like the one below in cases where there are more than 7 fields. please tell me how to correct that. i am really bad at shell scripting and I am just in learning phase..

Code:
sblp008  2007-03-20 10:45:22  Running                                261451    BMilstead4755  10718   eCustomerCMEObjMgr_enu

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help on parsing Oracle RMAN output for string and print sections of a file

Hi, I need some advise on how to print 'sections' of the attached file. I am searching for some that says Marked Corrupt and print some lines after it. At the moment I am running the command below: sed -n -e '/Marked Corrupt/{N;N;p;}' rman_list_validate.txtThis gives me the following... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Shell Programming and Scripting

Help: Parsing a file to new output files

I have an output file similar to this >HWI-ST766:129:D0WJDACXX:4:2308:16645:199681.1 /start=1 /end=100 /strand=+ Eukaryotic18S_rRNA GATTAAGCCATGCATGTGTAAGTTTAAAGTCCTAGAAGGATGAAACTGCGGACGGCTCAT TATAACAGTAATAGTTTCTTTGGTTAGTATCTATAAGGAT >HWI-ST766:129:D0WJDACXX:4:2308:2922:199946.1 /start=1... (4 Replies)
Discussion started by: fozrun
4 Replies

3. Shell Programming and Scripting

Help in parsing XML output file in perl.

Hi I have an XML output like : <?xml version="1.0" encoding="ISO-8859-1" ?> - <envelope> - <body> - <outputGetUsageSummary> - <usgSumm rerateDone="5"> - <usageAccum accumId="269" accumCaptn="VD_DP_AR" inclUnits="9999999.00" inclUnitsUsed="0.00" shared="false" pooled="false"... (7 Replies)
Discussion started by: rkrish
7 Replies

4. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

5. Shell Programming and Scripting

Parsing output

I need to parse the following out put and determine if the USB is a DISK and whether or not it's External. If an HBA line contains "USB" then does the next line contain "DISK" and "External". 0:0,31,0: HBA : (aacraid,1) AAC SCSI 0,0,0: DISK : Adaptec ASR4800SAS Volu0001 ... (6 Replies)
Discussion started by: lochraven
6 Replies

6. Shell Programming and Scripting

need help in Parsing a CSV file and generate a new output file

Hi Scripting Gurus, I am trying to parse a csv file and generate a new output file. The input file will be a variable length in turns of rows and columns. output file will have 8 columns. we have three columns from the header for each set. just to give little bit more clarification each row... (15 Replies)
Discussion started by: vkr
15 Replies

7. Shell Programming and Scripting

parsing output

I have a file that contains the output of the ls -iR command, something like this: ./results: 2504641011 result_1410 2500957642 result_525 2504641012 result_1425 2500957643 result_540 ./tests/1: 2500788755 1 2500788743 1000 ./tests/2: 2500788759 3 2500788758 999 ... (6 Replies)
Discussion started by: looza
6 Replies

8. Shell Programming and Scripting

Problem with parsing a large file

Hi All, Following is the sample file and following is the op desired that is the last entry of each unique first field is required. My solution is as follows However the original file has around a million entries and around a 100,000 uniques first fields, so this soln.... (6 Replies)
Discussion started by: gauravgoel
6 Replies

9. Shell Programming and Scripting

Problem parsing line in file

I am VERY new to unix scripting. I am having trouble parsing a line into fields for further processing. I have this script: #bin/sh cat ztest2.txt | while read line do zvar1=`echo $line | cut -f6` echo "zvar1 is " $zvar1 done ******************** ztest2.txt looks like: 1 ... (2 Replies)
Discussion started by: rlwilli
2 Replies

10. Shell Programming and Scripting

problem parsing process-output

HI all! I have a problem parsing the output of another process. The output is like this (C): printf("\rCheck exist: %d/%d",idx,pBF->NBits()); The aim of the script I'm coding is to save in a separate file the last output line of first process. This is the script now (Shell script): ... (3 Replies)
Discussion started by: victorin
3 Replies
Login or Register to Ask a Question