Creating file from an existing file using CUT, is it the best option?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating file from an existing file using CUT, is it the best option?
# 1  
Old 05-30-2011
Creating file from an existing file using CUT, is it the best option?

Dear All,

I have a requirement in which i have to load a file placed in FTP location onto my database. The process i'll follow is as below:
1) Get the files using FTP.
2) Create the desired load files as i have to load only 19 fields out of the 104 available in the file.
The fields i require can only be distinguished using their position. E.g 1-3 is one value, 5th field is another, 16-33 is another and so on for 19 fields.

I'm using CUT command to create a new file which will have "|" as delimiter. So while cutting the fields i'm appending the delimiter.
3) The file created above will then be used to load into database, pipe "|" being the delimiter using SQLLDR utility.

My concern is the step no. 2), as even for a file of length 10000 (each line 3159), it takes around 20 minutes Smilie. And i have to process around >7500000 records per day.

Is there any other method to achieve wht i want in a much shorter time Smilie?

I'm new to Unix, so please point out if you see any area for improvement. Smilie

Unix box is : SunOS 5.8

Thanks!!

Last edited by abhishekakaomi; 05-30-2011 at 08:03 AM.. Reason: Updating
# 2  
Old 05-30-2011
Try for a chance..
Code:
while read LINE
do
 SQL=
 for i in 1-3 5 18-33 48-63 64-65 66-83 84-115 116-147 259-260 261-292 303-306 307-310 326-327 328-333 334 2126-2127 2206-2219 2220-2225 2226-2237
 do
  SQL=${SQL}$(echo "$LINE" | cut -c $i)"|"
 done
 echo $SQL >> test_load_file.txt
done < XYZ.cdr

This User Gave Thanks to clx For This Post:
# 3  
Old 05-30-2011
First, various *nix flavors of cut are very slow because they read a byte at a time. Try awk with substr. Make sure you use the C locale.
Second, with sqlldr you don't need to create a temp file to load. You can just mention the columns you need with positions and lengths in your control card. My experiences tell me it will be very fast.
This User Gave Thanks to binlib For This Post:
# 4  
Old 05-30-2011
upload input data file , maybe you needn't cut command at all.

if the column split by space or other, we can take them directly by:

Code:
awk '{print $2, $5, etc}' your_data.file

This User Gave Thanks to rdcwayx For This Post:
# 5  
Old 05-31-2011
Replies

Hi All,

Thanks for replying.

@binlib -->
I have tried using AWK but it gives "value too long error".
And, i didn't know if i there was a way to pick data position-wise in SQLLDR.
Could you please share an example on the file sample feed file i'm attaching??Smilie

@rdcwayx -->
There is no delimiter in the feed file, i'm only aware of the string positions which i require Smilie.

@anchal_khare -->
Will try out your method Smilie

Also, i am going to try one method, in which i'm thinking of placing a delimiter "|" in positions require using SED and then taking out the required fields using NAWK. Will keep you posted on status of the process.

Regards.
# 6  
Old 05-31-2011
You can also write a control file for sqlldr which will do just that.

Check POSITION syntax in sqlldr control files, it should be just what you are looking for.
i would write some example but i'm home, don't have access to oracle, but there is plenty online.
This User Gave Thanks to Peasant For This Post:
# 7  
Old 05-31-2011
If awk have "value too long error", try this:

Code:
while read line
do
  # E.g 1-3 is one value, 5th field is another, 16-33 is another and so on 
  echo ${line:1:3} ${line:5:1} ${line:16:17} ......
done < infile

This User Gave Thanks to rdcwayx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Creating the script for updating or replacing the existing http.conf file

Hi I need some help with a task, i am an absolute newbie to any form of shell scripting and request guidance. I have been building a proxy server using the apache mod proxy currently my solution is working , but i need to automate the process , suppose if any changes need to be made on... (0 Replies)
Discussion started by: satej
0 Replies

2. Shell Programming and Scripting

Need help in creating a file in required format form another existing file

I have a text file with contents like this: a,b,c, d~e,f,g,h~i,j ,k,l,m~n,o,p,q~ I need to convert this file into this format unix shell script commands: a,b,c,d~ e,f,g,h~ i,j,k,l,m~ n,o,p,q~ as you may have noticed, I need to retain the ~ signs at the end. Any help is greatly... (3 Replies)
Discussion started by: harsha1238
3 Replies

3. Shell Programming and Scripting

.sh file To rename existing file and copy new file

Hi All, I am very new to shell scripting . In my current task i want to create .sh file that will rename the existing file with appending _bu in it. And then copy new file . e.g if i have file linuxFirst.java then i want to rename it to linuxFirst_bu.java ..Then want replace with latest... (1 Reply)
Discussion started by: maheshkaranjkar
1 Replies

4. Shell Programming and Scripting

Creating a new file based on existing file

Hello Guys , I need an another help regarding the below problem. I want to create a new file based on the existing file ,where two columns will be changed according to user input .(say column 4 and column 5) Please let me know how to proceed with Thanks (3 Replies)
Discussion started by: Pratik4891
3 Replies

5. Shell Programming and Scripting

folder existing and file existing

I want to look into a folder to see if there are any folders within it. If there are, I need to check inside each folder to see if it contains a .pdf file So If /myserver/myfolder/ contains a folder AND that folder conatins a .pdf file do X Else do Z I may have multiple folders and... (4 Replies)
Discussion started by: crowman
4 Replies

6. Shell Programming and Scripting

Creating/ammending Name Column in existing .txt file

With the help of this forum, I have a script with the following output: chr7 27104483 27105154 chr7 27106872 27110789 chr7 27111956 27112830 chr7 27114388 27125180 chr7 27126966 27131260 chr7 27135440 27137796 which was created by the following script: awk '1 == NR || $NF >= 1000 {... (6 Replies)
Discussion started by: awknerd
6 Replies

7. Shell Programming and Scripting

Creating a csv file based on Existing file

Hi I am Newbie to Unix.Appreciate Help from forum user would loada b.Csv File(Below example) in /data/m/ directory.Program need to read the b.csc to extract certain column and create a new file /data/d/ directory as csv file with new name. User File Format 1232,samshouston,12345... (3 Replies)
Discussion started by: skywayterrace
3 Replies
Login or Register to Ask a Question