how to transfer values from one big text file to another


I dont know where to place this question, but any ideas will be greatly apprecciated.
im having two text files- lets say A and B
A is having values like this
1 0 0 1
2 0 1 1
3 0 0 -4
4 0 0 -4

and B is having values like

1…1.4910967E+003  8.7261375E+002  1.1463431E+003  -3.0539021E+002  1.9476335E+002   -3.5904820E+002

so what i want is to bring the values from A into B where last number is less than zero, in the above example they are 3 and 4th rows. So i want to bring in the 3 and 4 into the B file.

the problem is i cannot import it into excel as the file has more than 65000 rows and also matlab cannot do this function.

can somebody tell me how i could achieve this....

I need only the correspording rows from the A file, and the chosed rows should build a new table, if possible in turn, with the original sequence. The A file has only a function, to help us to decide which row  be useful in the second file
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If I understand correctly you will need a raf:
I sugest you to use StreamTokenizer to operate on this algo.

Have you ever used script languages, like awk or perl?
It would be ideal solution for your problem. You just need a simple script to read file A, filter-out the lines you need, and print them. Get yourself an awk or perl interpreter, and ask this question in the perl channel.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

vihar123Author Commented:
are there any free tools that can do this, i dont want to program, and is it possible with excel to do the task is just getting those minus values into an other txt file, i dont want to write a new prg as it will not be of any use later

actually these values are retreived through matlab and these files are quite big, more than 70,000 i really dont know if i can do it with excel.....or other tools
Looks like you will have to write a program it looks like Excel is limited to 65535 rows.

Using programs, the # of rows would not matter, because a program can be written to just process 1 line at a time.  Here is how I would do it in Awk and other UNIX type utils:
ProcessA.awk (1 line file)
$NF<0 {print $0}

To run:
awk -f ProcessA.awk  A.txt > tmpA.txt
cat  B.txt tmpA.txt>newB.txt

Now 'newB.txt' will contain B+all of the rows from A where the last field is < 0
If you don't have access to Unix, you can download GAWK, cat (and other unix utils) at

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vihar123Author Commented:
i havent used it but ill accept this answer

thanks :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.