writing the value from a file into a table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting writing the value from a file into a table
# 1  
Old 09-18-2006
writing the value from a file into a table

guys..

I have a requirement like this. I need to write the output of a log file into a table. the logfile looks something like this

Code:
SV_NAME  CC_NAME              CP_DISP_RUN_STATE  
-------  -------------------  -----------------  
sble01   ALLTEL WorkMon24Hrs  Running

I would like to store each of these values into a variable.

eg (sble01 into a variable called $SV_NAME) an I will insert into tables using these variables.
I want to grab this output using shell script and insert into the table also using shell script. help me out!!

thanks guys.
# 2  
Old 09-18-2006
Since you have shown only one line and assumed second field always contain two words
Code:
while read SV_NAME CC_NAME1 CC_NAME2 CP_DISP_RUN_STATE 
do
    CCNAME="$CC_NAME1 $CC_NAME2"
    # code for inserting into table
done < file

if this doen't work show your log file
and you may be need to change the delimiter if necessary
# 3  
Old 09-19-2006
Hi Anbu, thanks for the reply. The log file looks like this.

Code:
Siebel Enterprise Applications Siebel Server Manager, Version 7.5.3.12 [16272] 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 1 server(s) out of a total of 1 server(s) in the enterprise

srvrmgr:sble01> list component '' show SV_NAME, CC_NAME, CP_DISP_RUN_STATE

SV_NAME  CC_NAME                                            CP_DISP_RUN_STATE  
-------  --------------------------------------------------------------  -----------------  
sble01   WebOrders WorkActn                               Online             
sble01   WebOrders WorkMon                                Running            
sble01   Alert 4 Hrs                                              Running            
sble01   Blackberry HC                                          Running            
sble01   Blackberry LM                                          Running            
sble01   WorkMon24Hrs                                         Running            
sble01   WorkMonImmediate                                   Running

From this log file I need to extract specific text. For eg) I need to get the first values sble01 into a variable called $SV_NAME, WebOrdersWorkActn in a variable called cc_name and online in a variable called status.

similarly I want to get the second and third values as well.

how do i do that.

thanks
Ragha
# 4  
Old 09-19-2006
Code:
sed -n "/^SV_NAME/,$ p" file | awk '
NR > 2 {n = split($0,arr," ")
printf("%s|",arr[1])
for( i = 2; i <=n-1;++i) printf("%s ",arr[i])
printf("\b|%s\n",arr[n]) }' > temp


old_IFS=$IFS
IFS="|"
while read SV_NAME CC_NAME CP_DISP_RUN_STATE
do
# code for inserting into table
done < temp
IFS=$old_IFS

rm temp

if you dont want space in second field replace with this in above code
Code:
for( i = 2; i <=n-1;++i) printf("%s",arr[i])
printf("|%s\n",arr[n]) }' > temp

# 5  
Old 09-19-2006
thank you very much for the reply anbu. i really appreciate that. i am getting an error in the code. I have shown below as to where I am getting the erroe.

Code:
sed -n "/^SV_NAME/,$ p" file | awk '
NR > 2 {n = split($0,arr," ")
printf("%s|",arr[1])
for( i = 2; i <=n-1;++i) printf("%s ",arr[i])
printf("\b|%s\n",arr[n]) }' > temp


old_IFS=$IFS
IFS="|"
while read SV_NAME CC_NAME CP_DISP_RUN_STATE
do
# code for inserting into table
done < temp  <------------ gets an error like this "done unexpected"
IFS=$old_IFS

rm temp

Thanks
# 6  
Old 09-19-2006
Add your code there and tell me if you get error
# 7  
Old 09-19-2006
This is the full code. It includes my code as well as yours. This is how it looks.

[CODE]

#!/bin/ksh
#
# Purpose: - Turn on Workflow Monitor agents that are not in 'running'/'online' state

umask 000
export LT=`date +%Y%m%d_%H%M%S`

if [ -f ./WorkflowMon_env.rc ]
then
. ./WorkflowMon_env.rc
else
echo "FATAL: Error sourcing Workflow Server Components!" >> error.log
exit -1
fi

# Obtain the secure username and password (if it exists)
#
if [ -f "$BATCH_USER_DIR/batch_user.ksh" ]
then
TMPPWD=`pwd`
cd $BATCH_USER_DIR
. ./batch_user.ksh
RTNCD=$?
cd $TMPPWD
if [ $RTNCD = 0 ]
then
export SIEBEL_USERNAME=$USERID
export SIEBEL_PASSWORD=$PASSWORD
else
echo "FATAL: batch_user.ksh returned an error ($RTNCD)" >> error.log
exit -1
fi
else
echo "ERROR: batch_user.ksh does not exist, unable to source in variables" >> error.log
exit -1
fi
export temp_output=$BATCH_USER_DIR/WorkflowMon/log/temp_$LT.out
sqlplus -S n9912499/n9912499@acsblest <<!
CREATE TABLE temp
(status varchar(20),
comp_name varchar(100),
srvr_name varchar(10));
!

x=`echo ${#wfname[*]}<<eof7
eof7`
((x=x+1))
echo $x
i=0

while [ $i -lt ${#wfname[*]} ]
do

$SIEBEL_ROOT/bin/srvrmgr -g $SIEBEL_GATEWAY -e $SIEBEL_ENTERPRISE -s $SIEBEL_SERVER -u n9912499 -p n9912499 -c "list component '${wfname[$i]}' show SV_NAME, CC_NAME, CP_DISP_RUN_STATE" -o "$temp_output"

sed -n "/^SV_NAME/,$ p" < $temp_output | awk '
NR > 2 {n = split($0,arr," ")
printf("%s|",arr[1])
for( i = 2; i <=n-1;++i) printf("%s ",arr[i])
printf("\b|%s\n",arr[n]) }' > temp

((i=i+1))


done

[\CODE]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Getting Rid of Annoying Bootstrap Table Borders and Wayward Table Lines

Bootstrap is great; but we have had some issues with Bootstrapped <tables> (and legacy <fieldset> elements) showing annoying, wayward lines. I solved that problem today with this simple jQuery in the footer: <script> $(function(){ $('tr, td, fieldset,... (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

Perl: Writing table values to a file

I have a file like this, 1,a,saurav 2,b,rout I want to show this file in a perl cgi page table and want to add a column which will contain a text box. There I will give some manual input, which will be written to the existing file(or a new file) in below format. 1|a|saurav|bangalore... (2 Replies)
Discussion started by: sauravrout
2 Replies

3. Shell Programming and Scripting

Build a table from a list by comparing existing table entries

I am new to this shell scripting.... I have a file which contains list of users. This files get updated when new user comes into the system. I want to create script which will give a table containing unique list of users. When I say unique, it means script should match table while parsing... (3 Replies)
Discussion started by: dchavan1901
3 Replies

4. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

5. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

6. UNIX for Dummies Questions & Answers

Creating a condensed table from a pre-existing table in putty

Hello, I'm working with putty on Windows 7 professional and I'd like to know if there's a way to gather specific lines from a pre-existing table and make a new table with that information. More specifically, I'd like the program to look at a specific column, say column N, and see if any of the... (5 Replies)
Discussion started by: Deedee393
5 Replies

7. Shell Programming and Scripting

Writing file name and date from LS command into a file to be imported into mysql

I am looking to do a ls on a folder and have the output of the ls be structured so that is is modificaiton date, file name with the date in a format that is compatible with mysql. I am trying to build a table that stores the last modification date of certain files so I can display it on some web... (4 Replies)
Discussion started by: personalt
4 Replies

8. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

9. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

10. Shell Programming and Scripting

help for writing shell script to export table data

Hi All, I need to write a shell script(ksh) to take the tables backup in oracle(exporting tables data). The tables list is not static, and those are selecting through dynamic sql query. Can any body help how to write this shell script. Thanks, (3 Replies)
Discussion started by: sankarg
3 Replies
Login or Register to Ask a Question