how to transfer values from one big text file to another

Posted on 2004-11-24
Last Modified: 2010-03-31

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
Question by:vihar123
    LVL 35

    Expert Comment

    If I understand correctly you will need a raf:
    LVL 6

    Expert Comment

    I sugest you to use StreamTokenizer to operate on this algo.

    LVL 1

    Assisted Solution

    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.

    Author Comment

    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
    LVL 21

    Expert Comment

    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
    LVL 21

    Accepted Solution

    If you don't have access to Unix, you can download GAWK, cat (and other unix utils) at

    Author Comment

    i havent used it but ill accept this answer

    thanks :-)

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Fix45 challenge 15 67
    wordsCount challenge 10 49
    array6 challenfge 6 49
    countPairs challenge 7 39
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now