Processing files using ksh shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Processing files using ksh shell
# 1  
Old 03-17-2010
Processing files using ksh shell

I need to write a Shell Script to process a huge folder of nearly 20 levels.I have to process each and every file and check which files contain lines like select insert update
When I mean line it should take the line till I find a semicolon in that file. I should get a result like this
Code:
  C:/test.java   select * from dual
C:/test.java   select * from test
C:/test1.java  select * from tester
C:/test1.java  select * from dual

and so on.Right now I have a script to read all the files
Code:
  #!bin/ksh

FILE=<FILEPATH to be traversed>
TEMPFILE=<Location of Temp file>
cd $FILE    
for f in `find . ! -type d`; 
do
cat $FILE/addedText.txt>>$TEMPFILE/newFile.txt
cat $f>>$TEMPFILE/newFile.txt
rm $f
cat $TEMPFILE/newFile.txt>>$f
rm $TEMPFILE/newFile.txt
done

I have very little knowledge of awk and sed to proceed further in reading each file and achieve what I want to.Can anyone help me in this


I am using Solaris so only nawk will work.

Last edited by vino; 03-17-2010 at 05:11 AM.. Reason: added code tags
# 2  
Old 03-17-2010
You can make use either of the below snippet inside your loop.

Code:
awk '/select|insert|update/ { _s=_s" "$0; f=1 } f==1{print} /;/ { f=0; } ' < file >sqlfile
# or,
perl -lane 'if (/select|insert|update/){ $str .= $_; $f=1 }print if $f==1;  $f=0 if /;/; ' < file >sqlfile


Last edited by dennis.jacob; 03-17-2010 at 05:28 AM.. Reason: Modified to handle the o/p redirection
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh processing options and parameters

I have a requirement where I need to process both options and parameters. command line call ie xxx.ksh -sid TEST1 -search_str LOCKED user1 user2 ..... I am using the following peice of code but I am usure how I can loop through all my parameters user1, user2, ... Note at the minium... (2 Replies)
Discussion started by: BeefStu
2 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

Moving log files based on month - help with ksh shell script

Hello, I'm trying to move the log files from the parent directory to respective monthly folder and I would be running this script on a weekly basis through cron. I'm new to this scripting and here is what i could come up and it runs without really doing anything. I even tried placing echo... (2 Replies)
Discussion started by: jusblues
2 Replies

4. Shell Programming and Scripting

ksh shell script to add date (YYYYMMDDHHMISS) to all .txt files in a folder

Everyday 15 files are written to a folder \app\where\thefiles\are\destined\CURRFOLDER Task1: I need to add date in YYYYMMDDHHMISS format to each of them. Example: File: ACCOUNT.txt Should be updated as: ACCOUNT_20101005175059.txt Task 2: After I update the files, they need to be ... (2 Replies)
Discussion started by: Duminix
2 Replies

5. Shell Programming and Scripting

How to unzip files from folder in shell script (ksh)?

I have a folder (C:\shellprg\input\) containing .CSV, .zip, .gz files. 1] I want to find all .zip/.gz files from folder (C:\shellprg\input\). 2] unzip/uncompress files into the same folder (C:\shellprg\input\) through shell script. I am using below commands for unzip files, unzip <filename>... (2 Replies)
Discussion started by: Poonamol
2 Replies

6. Shell Programming and Scripting

get all files from a directory and pass the files for processing

Hi All, I have a directory in which there will be several files. i want to get all the files and pass it to a piece of code for processing on the files. This is the piece of code which does the processing. tr "\n" "|" < (log file name) | tr "$" "\n" > output echo ' ' >>output while... (1 Reply)
Discussion started by: suresh_kb211
1 Replies

7. Shell Programming and Scripting

KSH script -text file processing NULL issues

I'm trying to strip any garbage that may be at the end of my text file and that part is working. The problem only seems to be with the really long lines in the file. When the head command is executed I am directing the output to a new file. The new file always get a null in the 4096 position but... (2 Replies)
Discussion started by: geauxsaints
2 Replies

8. Shell Programming and Scripting

Processing files

Hi I have the folowing input file, the file looks like below sftp> . .. archive x001_ameint*.zip x001_ameint_1.zip x001_ameint_2.zip x001_REPORTS*.zip x001_REPORTS_1.zip sftp> I want my output to look like this x001_ameint*.zip x001_ameint_1.zip x001_ameint_2.zip (1 Reply)
Discussion started by: ramky79
1 Replies

9. Shell Programming and Scripting

Two files processing

I have the following two files: 1st File: 1:1:100 2:101:400 3:401:450 4:451:600 5:601:980 6:981:1500 7:1501:1600 8:1601:1800 9:1801:2000 2nd File: 30 50 80 700 (2 Replies)
Discussion started by: moutaz1983
2 Replies

10. Shell Programming and Scripting

Processing a file in shell

I have a file which is having enrties like entry-id 1 ABC : value DEF :value GHI :VALUE entry-id 2 ABC : value DEF :value GHI :VALUE entry-id 2 ABC : value DEF :value GHI :VALUE and so on .. .wht i want to do is (1 Reply)
Discussion started by: msbinu
1 Replies
Login or Register to Ask a Question