Computing.Net > Forums > Windows 2000 > Script for parsing text files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Script for parsing text files

Reply to Message Icon

Name: gromul
Date: November 29, 2005 at 14:58:41 Pacific
OS: XP PRO
CPU/Ram: AMD 2000+ / 1GB
Comment:

If the text file can have specific lines in random order, can a script be written to copy those lines in the same order?

I.e.

text file #1:
string1
string2

text file #2:
string2
string1

Now if I have something like this in the script:
find string1 > newTextFile
find string2 > newTextFile

it will work correctly on one file but not on the other one.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 29, 2005 at 22:43:31 Pacific
Reply:

I'm not quite clear on what you want to do, but, in general, FIND needs two parameters:

FIND "string" FILENAME.EXT

So if you want to append strings to a new output file:

find "string" < file1 >> newfile
find "string" < file2 >> newfile

Does that help?


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: gromul
Date: November 30, 2005 at 18:27:40 Pacific
Reply:

Ok. So

find "string1" < file1 >> newfile
find "string2" < file2 >> newfile

will correctly process textfile1:
string1
string2

but processing textfile2 will give:

string1
string2

instead of this:

string2
string1

How do I also account for which line is first in the original file?


0

Response Number 3
Name: Mechanix2Go
Date: November 30, 2005 at 23:28:50 Pacific
Reply:

Still not clear.


If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: gromul
Date: December 1, 2005 at 07:22:53 Pacific
Reply:

I want the lines to be found and inserted into a new file in the same order they were in original file. So whether the file has:
1
2
3

or

3
2
1

the output file should be the same. If I just do

find "1" < file1 >> newfile
find "2" < file2 >> newfile
find "3" < file1 >> newfile

for the second file (3,2,1) I'll get
1
2
3
which isn't in the original order.


0

Response Number 5
Name: Mechanix2Go
Date: December 1, 2005 at 07:38:11 Pacific
Reply:

Well, you're right.

But what's changing the order is the way in which you are using find.

If you use this set of FINDs:

find "1" < file1 >> newfile
find "2" < file2 >> newfile
find "3" < file1 >> newfile

your newfile will be in 1 2 3 order regardless of which file they were found in.

If that doesn't seem to make sense maybe I don't yet get the problem.


If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: gromul
Date: December 2, 2005 at 07:16:23 Pacific
Reply:

So is there a way to make the script process the file so the order depends on the original files, not the order of commands in the script?


0

Response Number 7
Name: Mechanix2Go
Date: December 3, 2005 at 02:48:47 Pacific
Reply:

Sorry, I'm willing to help but I don't get it.


If at first you don't succeed, you're about average.

M2


0

Response Number 8
Name: Lucid
Date: December 29, 2005 at 16:48:33 Pacific
Reply:

You might try asking this in one of the scripting forums. I'll just toss in two cents and say that you'll probably need to make each one into a variable. Then put whatever you want to find first into Variable1, whatever you want to find second into Variable2, and so on. Then you can put them into the new text file in whatever order you want.

Oh, and make sure to tell the techies what script language you want to use...


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: Script for parsing text files

Batch script for parsing text file www.computing.net/answers/windows-2000/batch-script-for-parsing-text-file/63351.html

Reading a text file from a script www.computing.net/answers/windows-2000/reading-a-text-file-from-a-script/65233.html

Just Text Files but..... -->SQL DTS www.computing.net/answers/windows-2000/just-text-files-but-sql-dts/44581.html