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
#----- 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
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
sblp001|2007-03-19 17:20:49|Running||151115|anderst22@bp.|om 258|6 eCustomerCMEObjMgr_|nu
This should actually read like below
sblp001|2007-03-19 17:20:49|Running||151115|anderst22@bp.com |2586| eCustomerCMEObjMgr_enu
Please help oyt guys. thanks in advance