#!/usr/bin/perl -w

while(<>) {
	if (/^\tsed -i( -e)? (['"])([^'"]*)['"]\s(.*)/) {
		chomp;
		my ($quote, $expr, $file) = ($2, $3, $4);
		if ($quote eq "'") {
			print "\ted -s $file <<-\\EOF\n";
		} else {
			print "\ted -s $file <<-EOF\n";
		}
		if ($expr =~ /^\//) {
			print "\tg$expr\n";
		} else {
			print "\t,$expr\n";
		}
		print "\tw\n";
		print "\tEOF\n";
	} elsif (/^sed -i( -e)? (['"])([^'"]*)['"]\s(.*)/) {
		chomp;
		my ($quote, $expr, $file) = ($2, $3, $4);
		print "ed -s $file <<-EOF\n";
		if ($expr =~ /^\//) {
			print "\tg$expr\n";
		} else {
			print "\t,$expr\n";
		}
		print "\tw\n";
		print "\tEOF\n";
	} else {
		print;
	}
}
