Sponsored Content
Full Discussion: Looping through Files
Top Forums Shell Programming and Scripting Looping through Files Post 302839623 by Kolas79 on Friday 2nd of August 2013 06:08:26 AM
Old 08-02-2013
IBM Looping through Files

Hi all ,

I am new on this forum . I have to face a particoular implementation issue and I need some help .

Requirement :
I need to read a particoular file (an xml file) and after reading it I need to call an Oracle Stored Procedure passing the content of the file as paramenter , in order to update a particoular CLOB column on a table .

This the code I used (I'm using ksh on AIX 5.3 o.s.) .
Code:
#!/bin/ksh
# Shell Type : Korn Shell

SetXMLClob()
{
	echo "Starting SetXMLClob function....."
	LOGID=$2
	FILENAME=$3
	PROCEDURE_NAME=$4
	LOGFILE=$1/Log/$PROCEDURE_NAME"_"$LOGID.log
	export LOGFILE
	VALUE=$(cat $FILENAME | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g')	
	LENGTH=`expr length "$VALUE"`
	VALUE=`expr substr "$VALUE" 3 "$LENGTH"`
	echo $VALUE
	CHAR="'"
	while [ $LENGTH -gt 1 ];
	do
		SUBVALUE=`expr substr "$VALUE" 1 999`
		SUBLENGTH=`expr length "$SUBVALUE"`
		SUBVALUE=$CHAR$SUBVALUE$CHAR
		echo $SUBVALUE
		echo $LENGTH
		export SUBVALUE
		$1/spool_procedure.sh "$PROCEDURE_NAME" "'"$LOGID"'"
		
		if [ $SUBLENGTH -ge $LENGTH ]; then
			LENGTH=0
		else
			INDEX=`expr $SUBLENGTH + 1`
			VALUE=`expr substr "$VALUE" "$INDEX" "$LENGTH"`
			LENGTH=`expr length "$VALUE"`
		fi
	done
}

################################################### MAIN BODY
case $1"" in	
	"/SET") 	
		echo "----------------------" >> $LOGFILE
		SetXMLClob $2 $3 $4 $5;;
esac

Here the sub procedure called
Code:
PROC_NAME=$1
ROWID=$2

USER=$USERNAME
PASS=$PSW
CONNECTSTRING=$SID_ORACLE
#cd $LOCAL_CORE_FOLDE

echo ------------------------- >> $LOGFILE
echo Start: $DATESTAMP     >> $LOGFILE
echo LogId: $ROWID     >> $LOGFILE
# Now call the file spool sqlplus script 
( echo "CONN $USER/$PASS@$CONNECTSTRING"
  echo "EXEC $PROC_NAME("$ROWID","$SUBVALUE")"
  echo "EXIT"
) | sqlplus -s /NOLOG >> $LOGFILE

SUBVALUE=""
DATESTAMP_LOG=`date`
echo End: $DATESTAMP >> $LOGFILE

But this is not with too large files (>300 K)

I think the best solution is to loop through the file and extract at each interaction the first 1000 bytes of the file but I don't know how to do this in ksh .

Can someone help me?

thanks in advance ,

Kolas Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

looping files

Hi, I have a file a.lst which lists all files. as a.dat b.dat c.dat I want to process these files mentioned in the list file in a loop. Say I want to display only the first line of all the files a.dat , b.dat, c.dat. How can I go about it? Please help. (5 Replies)
Discussion started by: dharmesht
5 Replies

2. Shell Programming and Scripting

Help looping through files, please...

Okay... I've solved one problem. Here's the next. I'm writing a script file that needs to go through a directory and list all files in that directory. I'm using TCL/TK. I figured out how to go through the directory and how to loop through it, but I ran into a little problem. ... (2 Replies)
Discussion started by: kapolani
2 Replies

3. Shell Programming and Scripting

Looping on a list of files...

This isn't working for multiple files. It works for one file though. exists1=$(ls | grep gspp*) for FILES in $exists1 do echo "Loading $exists1" ... (23 Replies)
Discussion started by: lazerfoursix
23 Replies

4. Shell Programming and Scripting

Looping through files...

I posted this in the Solaris forum, but I don't think it's platform specific, so I'm posting it here. Here is the situation. We are a company that has been using a professional publishing system, the software is called "ProType". It runs on Solaris 2.4, however it is no longer supported and we... (6 Replies)
Discussion started by: Fred Goldman
6 Replies

5. Shell Programming and Scripting

Looping through 2 files simultaneously

Hi all, I'm having a problem with a script which should ultimately provide a filename by reading a value from file1 and file2 then join together. I'm planning to use a loop/ loops to get the values out of both files and create a single string unfortunately the code currently treats the second... (7 Replies)
Discussion started by: chris01010
7 Replies

6. Shell Programming and Scripting

looping through files

I am writing a ksh which has to load 7 files(.dat files) from input directory into oracle tables using sql loader. The process has to take each file at a time and once if it is loaded succesfully using sql loader into oracle tables then the process has to pick next file and load it into oracle... (2 Replies)
Discussion started by: vpv0002
2 Replies

7. Shell Programming and Scripting

looping through files with different extensions

Hi all, I am trying to make a for loop invoking files with different extensions (*.ugrd and *.vgrd) and I cant just make it work. Cant figure out how to load the files so as to use them in subsequent commands like the ones in this pseudo code. the files are arranged such that in one date for... (8 Replies)
Discussion started by: ida1215
8 Replies

8. Shell Programming and Scripting

Conditional Looping In Files

I have a req. where i need to read data from multiple files and take counts of row which satisfy the condition. e.g.: FILE1: Col1 Col2 Col3 12 ab cd 15 de fg 25 gh tm FILE2: Col1 Col2 Col3 21 ab1 cd1 13 de1 fg1 25 gh1 tm1 --- --- FILE-N... i need to find the count of rows... (6 Replies)
Discussion started by: kunal007
6 Replies

9. Shell Programming and Scripting

Not looping or creating files

So my script is supposed to repeat for every server in my file, but as of now it is getting stuck on my awk commands # Read file cred.txt (with one IP per line), connect to servers (one at a time), and download directory listing i=1 param=$(sed -n "{$1}p" $parm_dir/cdm_param.txt) #Get the last... (6 Replies)
Discussion started by: MJCreations
6 Replies

10. Shell Programming and Scripting

Looping through files in pairs

Hi all, Please guide. It has to do with parsing the input file names. I have a fairly large number of files, I want to do some operations on them in a pairwise fashion (every file has a pair). The names are in the following pattern, with the pairs of files named with _1 and _2 , the... (4 Replies)
Discussion started by: newbie83
4 Replies
IPTABLES-XML(1) 						  iptables 1.4.21						   IPTABLES-XML(1)

NAME
iptables-xml -- Convert iptables-save format to XML SYNOPSIS
iptables-xml [-c] [-v] DESCRIPTION
iptables-xml is used to convert the output of iptables-save into an easily manipulatable XML format to STDOUT. Use I/O-redirection pro- vided by your shell to write to a file. -c, --combine combine consecutive rules with the same matches but different targets. iptables does not currently support more than one target per match, so this simulates that by collecting the targets from consecutive iptables rules into one action tag, but only when the rule matches are identical. Terminating actions like RETURN, DROP, ACCEPT and QUEUE are not combined with subsequent targets. -v, --verbose Output xml comments containing the iptables line from which the XML is derived iptables-xml does a mechanistic conversion to a very expressive xml format; the only semantic considerations are for -g and -j targets in order to discriminate between <call> <goto> and <nane-of-target> as it helps xml processing scripts if they can tell the difference between a target like SNAT and another chain. Some sample output is: <iptables-rules> <table name="mangle"> <chain name="PREROUTING" policy="ACCEPT" packet-count="63436" byte-count="7137573"> <rule> <conditions> <match> <p>tcp</p> </match> <tcp> <sport>8443</sport> </tcp> </conditions> <actions> <call> <check_ip/> </call> <ACCEPT/> </actions> </rule> </chain> </table> </iptables-rules> Conversion from XML to iptables-save format may be done using the iptables.xslt script and xsltproc, or a custom program using libxsltproc or similar; in this fashion: xsltproc iptables.xslt my-iptables.xml | iptables-restore BUGS
None known as of iptables-1.3.7 release AUTHOR
Sam Liddicott <azez@ufomechanic.net> SEE ALSO
iptables-save(8), iptables-restore(8), iptables(8) iptables 1.4.21 IPTABLES-XML(1)
All times are GMT -4. The time now is 06:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy