• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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

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
jfz139
Asked:
jfz139
  • 5
  • 5
  • 3
1 Solution
 
maneshrCommented:
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
 
jfz139Author Commented:
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
 
maneshrCommented:


"..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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
jfz139Author Commented:
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
 
jfz139Author Commented:
>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
 
maneshrCommented:
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
 
maneshrCommented:
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
 
Kim RyanIT ConsultantCommented:
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
 
Kim RyanIT ConsultantCommented:
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
 
jfz139Author Commented:
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
 
jfz139Author Commented:
maneshr,

Thank you very much, too.

Jennifer.
0
 
maneshrCommented:
jfz139,

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

Sure!! Glad to know you got the solution you were looking for.
0
 
Kim RyanIT ConsultantCommented:
Happy to help, and that we didn't re-invent the wheel. Let me know of any furter queries on this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now