Solved

How to output a portion of a text file on windows 2000?

Posted on 2002-04-18
13
254 Views
Last Modified: 2008-03-03
Some say I need use perl to do that. But I am new to perl.
Could any one point me to some sample code to get started?

Thank you.

Jennifer
0
Comment
Question by:jfz139
  • 5
  • 5
  • 3
13 Comments
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
jfz139,

"..Could any one point me to some sample code to get started?.."

Do you have Perl installed on your system? How do you want to call this Perl script, from the command line, or via the browser?

Can you post the sample text file here? Also, can you describe what portion of the text file you want?

Pl. provide as much more detail as you can.

This will help you get a more accurate answer, faster.
0
 

Author Comment

by:jfz139
Comment Utility
Thanks for reply so fast.
OK, I believe I have perl install on my system.
It is a win 2000 machine. I want to call this perl from
command line.

The text file is saved in a *.txt file on C: drive.
It has many rows. So even if I want to use nodepad to
open it takes 5 mins. That is why I want to break it
up. It has the content from a database table.
I can not disclose its content for security reasons.

Do you need more info?

Thanks.

Jennifer
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility


"..OK, I believe I have perl install on my system. ..."
Can you please confirm tha with 100% confidence? I want to be sure that you can use any script that i post here.

"..It is a win 2000 machine. I want to call this perl from command line..."
Excellent!!!

"..I can not disclose its content for security reasons...."

And that is totally acceptable. That is the reason i want you to post a sample form of that data, with some junk info. This will give me some target to shoot for.

"....Do you need more info?.."
Yes. Can you please explain how the script will know what portion of the text file to extract?
Lets say the script has been able to get a portion of that file. What is the script then supposed to do with it?

Please explain in simple bullet points what exactly you want the script to do?

This will help you get a more accurate answer, faster.
0
 

Author Comment

by:jfz139
Comment Utility
Yes. Now I am certain I have perl (just contacted admin).
Here is a sample 3 lines of the file:

1497397     BBB     1305     Y13949.2     F     AARB
83746     CC     AECOUS     AAAA     4/1/2002 69000    
68471     0     -12667     2.6300     2.4450

Each line has a line break.

I would like to break this file into 2 smaller files.

Thank you.

Jennifer

0
 

Author Comment

by:jfz139
Comment Utility
>Lets say the script has been able to get a portion of that file. What is the script then supposed to
do with it?

I would like the script to break this file into two or more
files and save in different file name like file-1.txt, file-2.txt, etc.

Jennifer
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
jfz139,

"..break this file .."

How should the script break it? in half?

E.g. the file has 200000 lines, then 100000 lines will be in one file and the rest in the other.

Let me know
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:maneshr
Comment Utility
jfz139,

"..Now I am certain I have perl (just contacted admin)...."
Excellent!! This is great news indeed!!

"..Here is a sample 3 lines of the file:

                     1497397     BBB     1305     Y13949.2     F     AARB
                     83746     CC     AECOUS     AAAA     4/1/2002 69000    
                     68471     0     -12667     2.6300     2.4450

                     Each line has a line break.

                     I would like to break this file into 2 smaller files."

Do these 3 physically seperate lines form part of 1 single logical record?

Based on the input you have given, can you tell me what part of those 3 lines would go in each of the smaller files?

Let me know.
0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 100 total points
Comment Utility
Like many common problems, this has already been solved, first as a Unix utiltiy, but also in a perl version. The program is fairly complex and well documented, so I would recommend downloading it rather than try for a custom solution.
Index Page:
http://www.perl.com/language/ppt/src/split/index.html
The code itself, cut and paste text and save as split.pl http://www.perl.com/language/ppt/src/split/split.lafferty

To run it you would have to say: perl split.pl -l 100000 file1.txt
The 100000 means split every 100,000 lines. Of course you will need to find out how many lines in you r file, (maybe downlaod the wordcount utility, wc athttp://www.perl.com/language/ppt/src/wc/index.html) and half that. I think output files are named xaa, xzb, xac ...
0
 
LVL 19

Expert Comment

by:Kim Ryan
Comment Utility
The file output names should have been xaa, xab, xac ... xan. If you set a numeric limit of x lines, split will divide your file into as many pices as necessary. Also, you can use a programmers editor to easily view very large files, try www.textpad.com
0
 

Author Comment

by:jfz139
Comment Utility
Teraplane,

Yes, this is indeed what I want. I am looking at your
link:
 http://www.perl.com/language/ppt/src/split/split.lafferty

Also, I will try www.textpad.com

Thank you so much.

I may still have question on this, but I will accept your
answer.
0
 

Author Comment

by:jfz139
Comment Utility
maneshr,

Thank you very much, too.

Jennifer.
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
jfz139,

"..Thank you very much, too. .."

Sure!! Glad to know you got the solution you were looking for.
0
 
LVL 19

Expert Comment

by:Kim Ryan
Comment Utility
Happy to help, and that we didn't re-invent the wheel. Let me know of any furter queries on this.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now