On Aug 5, 2006, at 9:26 AM, Andrew Brown wrote:
I have a file like this
1 line...
line...
line...
2 line...
line...
line...
3 line...
and I would like to achieve this
1 line...
1 line...
1 line...
2 line...
2 line...
2 line...
3 line...
A simple job in Excel, but Excel screws up text given any chance it
gets and some of the lines are long. There is a tab after the
numbers and one at the start of every line without a number.
Any ideas? I can't write Perl.
Here's a filter that will do what you want. In your sample data there
is a tab before the numbers as well, so I allowed for that. The
filter looks on each line to see if it matches the pattern tab -
number - tab at the start, and if it does it sets the value of
$currnum to the number. Then it replaces the pattern tab - zero or
more numbers - tab at the start of the line with the pattern tab -
$currnum - tab, then prints the line back out.
Save the script with any name you want in your ~/Library/Application
Support/BBEdit/Unix Support/Unix Filters/ folder, then select the
text you want to apply it to and run it from the Unix Filters under
the #! menu.
#!/usr/bin/perl -w
while(<>) {
if($_ =~ /^\t([\d]+)\t/) { $currnum = $1 }
$_ =~ s/^\t\d*\t/\t$currnum\t/;
print $_;
}
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>