Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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
string2text file #2:
string2
string1Now if I have something like this in the script:
find string1 > newTextFile
find string2 > newTextFileit will work correctly on one file but not on the other one.

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 >> newfileDoes that help?
If at first you don't succeed, you're about average.M2

Ok. So
find "string1" < file1 >> newfile
find "string2" < file2 >> newfilewill correctly process textfile1:
string1
string2but processing textfile2 will give:
string1
string2instead of this:
string2
string1How do I also account for which line is first in the original file?

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
3or
3
2
1the output file should be the same. If I just do
find "1" < file1 >> newfile
find "2" < file2 >> newfile
find "3" < file1 >> newfilefor the second file (3,2,1) I'll get
1
2
3
which isn't in the original order.

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 >> newfileyour 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

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?

Sorry, I'm willing to help but I don't get it.
If at first you don't succeed, you're about average.M2

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...

![]() |
![]() |
![]() |

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