Save the following perl script as a filter and it should do the trick 
(worked on your sample data, did not test it any further then that):

#!/usr/bin/perl

while (<>) {
    #remove the line break character
    chomp($_);

    #split the line into the starting number and following text
    ( $number, $text ) = split( /\s*\#\s*/, $_, 2 );

    #add the text plus a space to any previous text found with the same 
number
    $text{"$number"} .= $text . " ";

}

#sort all the groups, which are identified by their number as their key in 
the hash "text"
foreach ( sort { $a <=> $b } keys(%text) ) {

    #change the extra space at the end of the group to a line break
    $text{$_} =~ s/ $/\n/;
    
   #print a "#" character and a space, followed by the text
    print "# " . $text{$_};

}


On Saturday, February 16, 2013 6:16:25 PM UTC-5, LuKreme wrote:
>
> I have a text file that is formatted like this: 
>
> 1#some text 
> 1#goes here 
> 1#not hard wrapped 
> 1#to the line length 
> 2#while other text 
> 2#is here 
> 3#some here 
> 4#also here 
> 4#and there and everywhere 
>
> and continuing on for a few thousand increments and many thousands of 
> lines. (that is, there are over 2000 numbers and over 5000 lines). 
>
> I need to end up with this: 
>
> # some text goes here, hard wrapped to the line length 
> # while other text is here 
> # some here 
> # also here and there and everywhere 
>
> (that is, I need to strip the numbers, but I need to keep each text block 
> together on a single line). 
>
> The specific formatting at the end isn't the issue, I can do that, it's 
> grouping the lines based on the numbering that is the issue. Even if I 
> could just get to 
>
> 1#some text #goes here #not hard wrapped #to the line length 
> 2#while other text #is here 
> 3#some here 
> 4#also here #and there and everywhere 
>
> That would get me close enough to deal with the rest of the formatting. 
>
> I was reading Chapter 8 thinking there was a way to do this with grep, and 
> I think there is a way with the negative look-ahead, but once again when 
> trying to figure it out my brain melted a little. 
>
> Something like (^\d+)#(.*)$ . . . (?!\1) 
>
> BTW, in googling for info, I found this page 
>
> <http://caspar.bgsu.edu/~courses/Stats/Labs/Handouts/grepadvanced.htm> 
>
> Which appears to simply be an html-ization of a portion of the BBEdit 
> manual. 
>
> -- 
> "There's sex and death and human grime in monochrome for one thin dime 
> and at least the trains all run on time but they don't go anywhere." 
>
>

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to