Reading files under a folder and formatting content of each file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading files under a folder and formatting content of each file
# 15  
Old 02-11-2011
Hi Pludi,
sorry to trouble you.My request is almost coming to please help me.I already started learning sed&awk i will definelty come up with good practice next time.

Output is coming like
Code:
INSERT INOT xxxxxx.sql VALUES(--------------------,
AAAAAAA,
BBBBBBB,
CCCCCCC,
3 records(s) selected );

INSERT INTO xxxxx.sql VALUES(--------------------,
AAAAAAA,
BBBBBBB,
CCCCCCC....
......
......
.......

21 record(s) selected.);

where i don't want tablename with .sql extension,first line (----------) to be deleted ,last line "(x records(s) selected)" to be delted.Totally out put should be.

Code:
INSERT into tab1 (AAAAAAA,
BBBBBBB,
CCCCCCC) select 
AAAAAAA,
BBBBBBB,
CCCCCCC
from tab1;

# 16  
Old 02-11-2011
If those lines are still coming in there's a difference between the layout of the input files you've given and reality. Can you post the first and last few lines of a file?
# 17  
Old 02-11-2011
The input file in each file is like this .its almost same as i have given at very first.Is there any problem with line number in first sed?

d,2d??


Code:
/home/db2inst/test/JAVA/DDL $ more file1.sql

COLUMNNAME 
--------------------
AAAA
BBBB
CCCC
3 record(s) selected.


Last edited by pludi; 02-11-2011 at 11:12 AM..
# 18  
Old 02-11-2011
OK, so there is an empty line before the column name that wasn't there before. No big deal, just change the 1,2d to 1,3d. However, there has to be something after the "last" line ("... selected"). Even if it's just an empty line. Please check this.

If there is something trailing, you'll have to change the first sed line to read (additions marked in red)
Code:
sed -e '1,2d; $d; /^[:space:]*$/d; /selected\.$/d' ${file} | \

# 19  
Old 02-11-2011
perfect its working fine.Only the next part should be another SELECT and all the columns like below.Can you pelase help me this the last attempt.

Code:
INSERT into tab1 (AAAAAAA,
BBBBBBB,
CCCCCCC) select 
AAAAAAA,
BBBBBBB,
CCCCCCC
from tab1;

This is only the last part left out.

we should repeat the 2nd SED again?

Last edited by rocking77; 02-11-2011 at 12:04 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Reading flat file content

is there any unix tools that can read the text files like through SQL queries? (ie in Hadoop, Impala DB support flat file query) (1 Reply)
Discussion started by: omykarshan
1 Replies

2. UNIX for Beginners Questions & Answers

How to get script to create a new file that lists folder content sorted by size?

I have a script that sorts and processes unsorted files to newly created directories. Its working great, but I am trying to understand the leanest method to get the script to create an additional file within each newly created directory that: Contains a list of all files in the directory... (4 Replies)
Discussion started by: Braveheart
4 Replies

3. Shell Programming and Scripting

Trouble reading content of file from a variable

Hi , i have a parameter which has path of a file. Now i need to have another parameter with the content of that file. I tried the belwo script , can any one please help. I dont want to use cat command to read. Can we do it with out using cat command. while read line do... (9 Replies)
Discussion started by: Ravindra Swan
9 Replies

4. Shell Programming and Scripting

search for content in files. Name of files is in another file. Format as report.

Hi I have multiple files in a folder and one file which contains a list of files (one on each line). I was to search for a string only within these files and not the whole folder. I need the output to be in the form File1<tab>string instance 2<tab> string instance 2<tab>string instance 3... (6 Replies)
Discussion started by: pkabali
6 Replies

5. Shell Programming and Scripting

Formatting Report and Reading data and fetching the details from contents file

Data I was trying to write shell script which will be return the output in the below format First i was trying to do these using sed. sed -n '/.ksh/p' mainksh.ksh sed -e 's/*\(.*\)/\1/g' mainksh.ksh $RUN_DIR, $SUB_DIR and the variables which will be defined in the profile file. when i am... (0 Replies)
Discussion started by: rameshds
0 Replies

6. Shell Programming and Scripting

Need to build Shell Script to search content of a text file into a folder consist several files

Have to read one file say sourcefile containing several words and having another folder containing several files. Now read the first word of Sourcefile & search it into the folder consisting sevral files, and create another file with result. We hhave to pick the filename of the file in which... (3 Replies)
Discussion started by: mukesh.baranwal
3 Replies

7. Shell Programming and Scripting

Reading several files and summing their content line-by-line

Hey, I am gettin a bit crazy with my script. I have several input datas with the same name (5.ill) in different folders (daysim_01, daysim_02, etc.). The 4. column of each of the data has to be summed with each other and then hass to be written in one new file. So file1: 1 1 0 1 2 1 1 2 ... (7 Replies)
Discussion started by: ergy1983
7 Replies

8. Shell Programming and Scripting

Problem in reading a file content

Hi, I am reading a file line by line using read line function of while loop. Each line contains 4 fields. I want to take these 4 values in 4 variables in each iteration so that i can use them in my script. The issue here is that my awk command is returning awkward results - Here is a sample line... (8 Replies)
Discussion started by: garman
8 Replies

9. UNIX for Advanced & Expert Users

Reading a file and sending mail based on content of the file

Hi Gurus, I am having an requirement. i have to read a list file which contains file names and send mail to different users based on the files in the list file. eg. if file a.txt exists then send a mail to a@a.com simillary for b.txt,c.txt etc. Thanks for your help, Nimu (6 Replies)
Discussion started by: nimu1979
6 Replies

10. Shell Programming and Scripting

reading a file name as soon as that files arrives into a folder

Hi, Thanks in Advance.. i have the following requirement, some one please help me.. An unix shell script has to pick up the file name from a folder as soon as that file comes into that folder. Regards, Alo (6 Replies)
Discussion started by: dtazv
6 Replies
Login or Register to Ask a Question