Generating files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generating files.
# 1  
Old 09-20-2008
Generating files.

I/P file name:- 20092008.txt
Check number of entries in i/p file by following command
ChkEnt -infl 20092008.txt -opfl 20092008_test.txt >count.txt

Dear Friends,
Please help me in automating following thing.

If output generated (count.txt) is having value more than 1000 i.e. say it has shown 3521 entries
Then, system should split file as follows

Splt -infl 20092008.txt -opfl 20092008_1.txt -b 0 -e 1000
Splt -infl 20092008.txt -opfl 20092008_2.txt -b 1001 -e 2000
Splt -infl 20092008.txt -opfl 20092008_3.txt -b 2001 -e 3000
Splt -infl 20092008.txt -opfl 20092008_4.txt -b 3001 -e 3521

Here the script should be smart enough to calculate number of files to be generated automatically by looking at total no of entries in original file i.e. 3521 in earlier example.

Thank you in advance.
I am waiting for your reply
Bye and take care
# 2  
Old 09-20-2008
split takes a linecount parameter.....iirs the default is 1000, i.e. it will split your file into 1000 line chunks.

is this not what you are after ?
# 3  
Old 09-20-2008
No, my system works differently, it does not split file by line count. It works on a logic n that logic is incorporated the command that i hv mentioned i.e. Splt
# 4  
Old 09-20-2008
aaah - you mean something like:

Code:
#  x=$(wc -l count.txt) ; y=0 

#  while [ $x -gt 1000 ]; do echo Splt -infl 20092008.txt -opfl 20092008_${y} -b $(expr $y \* 1000 + 1) -e $(expr $y \* 1000 + 1000); y=$(expr $y + 1); x=$(expr $x - 1000); done ; echo Splt -infl 20092008.txt -opfl 20092008_2 -b $(expr $y \* 1000 + 1) -e  $(expr $y \* 1000 + $x)
Splt -infl 20092008.txt -opfl 20092008_0 -b 1 -e 1000
Splt -infl 20092008.txt -opfl 20092008_1 -b 1001 -e 2000
Splt -infl 20092008.txt -opfl 20092008_2 -b 2001 -e 3000
Splt -infl 20092008.txt -opfl 20092008_2 -b 3001 -e 3521

# 5  
Old 09-20-2008
Dear Tytalus, thanx for your quick reply.
I m new to unix n all, so can u plz tell me following things

1. Can we use "cat" option i.e. cat count.txt to assign that count value to variable x?
e.g
x=`cat count.txt`

2. Honestly i coulnt undrstnd this statement.
while [ $x -gt 1000 ]; do echo Splt -infl 20092008.txt -opfl 20092008_${y} -b $(expr $y \* 1000 + 1) -e $(expr $y \* 1000 + 1000); y=$(expr $y + 1); x=$(expr $x - 1000); done ; echo Splt -infl 20092008.txt -opfl 20092008_2 -b $(expr $y \* 1000 + 1) -e $(expr $y \* 1000 + $x)
Can u jst tell me, is the script smart enough to handle even if a particular file has n number of records? or it can handle only 3521 entries?
# 6  
Old 09-20-2008
no worries.

cat will simply spew the file out.

wc will give you a word count (and the -l will be the number of lines alone).

Yes - the script should work for any length file - it simply sets a variable x as the number of lines, then repeatedly subtracts 1000 and spts out each individual command, until x' is less than 100 - then the loop finishes and it kicks out the final splt command
# 7  
Old 09-20-2008
Ohh wow, why this logic didnt strike me, was thinking about the logic since 2-3 days...
Any ways, will try this on Monday evening. Will let you know if I need more help.
Thanx a lot for your help.
Bye & God bless you,
All the best
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split Command Generating Incomplete Output Files

Hello All, May i please know how do i ensure my split command would NOT generate incomplete output files like below, the last lines in each file is missing some columns or last line is complete. split -b 50GB File File_ File_aa |551|70210203|xxxxxxx|12/22/2010 20:44:58|11/01/2010... (1 Reply)
Discussion started by: Ariean
1 Replies

2. Shell Programming and Scripting

Comparing two files and generating the report

Hi All, What am trying to do is generate the report by compating two files. File A ----------- 111 22222 3333 222 55555 7777 File B ----------- 11A 22222 3333 333 55555 7778 Now the report should be as follows Added: 333 55555 7778 Removed: (6 Replies)
Discussion started by: Prashantckc
6 Replies

3. Shell Programming and Scripting

Generating graphs for many number of files

Hi, I have a series of data files for which I wish to plot using "splot". Say, the files names are like: 950_data,951_data,952_data,......1000_data. For one file , say to plot 950_data, i write following lines into a single file and load it in the gnuplot as : gnuplot> load 'plot' ... (6 Replies)
Discussion started by: begin_shell
6 Replies

4. Shell Programming and Scripting

Problem with script generating files in directory recursively

I have a script which generates recursively some files in folders for a given root folder. I have checks for permissions and it works for all folders except one(i have 777 permission on it). When i try calling the script in problematic folder(problematic folder being root folder), script works as... (2 Replies)
Discussion started by: bb2
2 Replies

5. Shell Programming and Scripting

Generating MD5's of files

On my website I host a lot of files, and when people view the site, currently each time the page loads, I have PHP generating the md5 sums for the files right then and there. It was fine when my site was small, but now that's obviously very inefficient. Now I'd like to start generating MD5 sums... (4 Replies)
Discussion started by: GrdLock
4 Replies

6. Shell Programming and Scripting

Need help with generating m3u files in numbered directories

Hello: First, I have no idea what to search for on this task, so I'll just spell it out. I have the Bible in Audio format and each book is in a directory of it's own. 01 to 66 accordingly. I need a script to walk through each of them and ls *.mp3 > directory|book.m3u without the preceding... (2 Replies)
Discussion started by: Habitual
2 Replies

7. Shell Programming and Scripting

Generating an xml having information related to files in the directory

Hi all, Have to generate an xml having information related to files in the directory Suppose i have file file1.xml (datafile) file2.xml (datafile) file3.xml (metafile) Now i need to generate an xml in the format >> <?xml version="1.0" encoding="UTF-8"?> <AuditFile Version="2.0">... (8 Replies)
Discussion started by: abhinav192
8 Replies

8. Shell Programming and Scripting

Generating formatted reports from log files

Given that I have a log file of the format: DATE ID LOG_LEVEL | EVENT 2009-07-23T14:05:11Z T-4030097550 D | MessX 2009-07-23T14:10:44Z T-4030097550 D | MessY 2009-07-23T14:34:08Z T-7298651656 D | MessX 2009-07-23T14:41:00Z T-7298651656 D | MessY 2009-07-23T15:05:10Z T-4030097550 D | MessZ... (5 Replies)
Discussion started by: daccad
5 Replies

9. Shell Programming and Scripting

Generating files with time interval of fifteen minutes

Hi Guys, I have two dates as start date and end date.. i need to generate files within these two dates with time interval of half an hour.... i.e. Start Date=25/09/07 12:00:00 End Date=26/09/07 12:00:00 Now i need to generate files every half an... (0 Replies)
Discussion started by: aajan
0 Replies

10. Shell Programming and Scripting

Generating files of specific size

I've been working on getting a script to take size, dir name and file name variables from an input file and creating the same dir structure along with the file of specific size. An example of the input file: size/dirname/filename 2100/JAN_06/12345ABC.TCC 2354/FEB_06/24564XYZ.NOS... (2 Replies)
Discussion started by: nxd25
2 Replies
Login or Register to Ask a Question