?
Solved

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

Posted on 2002-04-18
13
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 6951693
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
ID: 6951729
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
ID: 6951762


"..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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jfz139
ID: 6951864
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
ID: 6951951
>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
ID: 6952100
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
 
LVL 16

Expert Comment

by:maneshr
ID: 6952105
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 400 total points
ID: 6952193
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
ID: 6952273
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
ID: 6953877
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
ID: 6953882
maneshr,

Thank you very much, too.

Jennifer.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6954170
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
ID: 6955169
Happy to help, and that we didn't re-invent the wheel. Let me know of any furter queries on this.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

764 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