Log in

View Full Version : anybody here use vi? Little help needed.



jasong
01-16-2007, 08:41 PM
I'm running LLR to attempt to find a prime for k=4 and base=9. Since, as the n-value increases the time per test increases, simply splitting the LLR file in two is suboptimal.

I'm hoping someone can give me a vi command that takes, first, all odd numbered lines and puts them in a file, then all even numbered lines and puts them into another file.

Also, a vi tutorial, so I don't have to bug you guys again, would be fantastic.

Bok
01-17-2007, 08:32 AM
Not sure you can do it directly in vi off the top of my head, but I'm assuming you have linux running? A quick shellscript or a simple perl program will do it easily enough..

#!/usr/bin/perl

$file = $ARGV[0];

open(DATA, $file) || die("Could not open file!");
@mydata=<DATA>;
close(DATA);
open (ODD, '>>odd.txt');
open (EVEN, '>>even.txt');

$i = 0;
foreach $line (@mydata)
{
if ($i % 2 eq 0){
print ODD $line;
} else {
print EVEN $line;
}
$i++;
}

Cut and paste the above into a file named split.pl (or whatever) and run it against the file in question like

./split.pl input.txt

and it will write out odd.txt and even.txt

As for a vi course, as usual Google (http://www.google.com/search?q=vi+tutorial) is your friend

Bok

alpha
01-17-2007, 08:59 AM
./split.pl input.txt

You probably won't be able to execute it like that unless you do this first, though it is only necessary once (dollar sign symbolises your shell prompt):

$ chmod +x split.pl
Or, just invoke it with perl itself:

$ perl split.pl input.txt