« Previous Next »

Thread: Need to pull pairs of lines from text file.

Last post 04-25-2007 6:09 AM by LogParser User : DEinspanjer. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 06-22-2006, 7:19 AM

    Need to pull pairs of lines from text file.

    I have a file with data similar to this:

     MTD Billed   MTD Paid Unapplied    MTD WOsYTD Billed   YTD Paid  Unapplied   YTD WOs
         William J. Smith
          21,036.74  4,188.01      0.00       0.03193,961.13 199,11.91       0.00     80.03
         Nancy Carlsbad
          1,981.50   6,091.78      0.00   4,24.93121,385.50 106,004.63       0.00  5,224.34
         Charles Cavern
           16,695.82  12,900.32      0.00       0.00 70,615.00  85,714.27       0.00      0.00

    I need to be able to output to a text file only the lines pertaining to "Nancy Carlsbad" (the lines ith her name and the following line directly below it). It is possible that her name may appear multiple times within the input file so I will need all lines where her name appears as well as the next line below her name in each instance.

    How can I do this?

     

    West

     

  • 06-23-2006, 5:04 PM In reply to

    RE: Need to pull pairs of lines from text file.

    LogParser can't really handle this type of data. I'd suggest moving to a scripting language such as Perl/Python/Ruby
  • 08-21-2006, 2:43 PM In reply to

    RE: Need to pull pairs of lines from text file.

    Performance will most likely degrade severely on large files, but using SQL IN gets the job done ...

    select Index,Text
     from YourData.txt
     where Index in (
    SELECT add(Index,1)
     FROM YourData.txt
     WHERE text like '%Nancy Carlsbad%'
    )
    or Index in (
    SELECT Index
     FROM YourData.txt
     WHERE text like '%Nancy Carlsbad%'
    )
    order by Index

  • 04-24-2007, 2:22 AM In reply to

    RE: Need to pull pairs of lines from text file.

    Thanx BigJ !!!!
  • 04-25-2007, 6:09 AM In reply to

    RE: Need to pull pairs of lines from text file.

    LogParser User : DEinspanjer:
    Quote: Performance will most likely degrade severely on large files, but using SQL IN gets the job done ... select Index,Text  from YourData.txt  where Index in ( SELECT add(Index,1)  FROM Yo...

    That's a good idea Big J. I'd be interested to know how it performs on a bigger file.

    I guess I didn't think about an IN subselect as a solution because I overlooked the fact that he only wanted rows pertaining to one person. I was thinking more along the lines of joining all the data rows with their associated names.
Page 1 of 1 (5 items)
Microsoft Communities