Sun751 has asked for the wisdom of the Perl Monks concerning the following question:

if my lines looks like this
#1 aba baba
#1 bsdb dbbsd
#1 sdh hsds
In vi how can i write regular exp to add new line in between # and 1.
# 1 aba baba Cheers

Replies are listed 'Best First'.
Re: (OT) Regular Expression
by ww (Archbishop) on Oct 09, 2009 at 11:13 UTC

    Though many Monks use vi, SOPW is not the appropriate place for a question strictly about vi.

    If this were a perl question... and if your output illustration reflects your actual desire ("# 1 aba baba Cheers" does not match "how can i write regular exp to add new line in between # and 1."):

    #!/usr/bin/perl use strict; use warnings; # 800208 my $test; while ( <DATA> ) { $test = $_; if ( $test =~ /#1 aba baba/ ) { chomp $test; print "$test Cheers\n"; } else { print "$test"; } } __DATA__ #1 aba baba #1 bsdb dbbsd #1 sdh hsds #1 aba baba #2 aba baba
Re: (OT) Regular Expression
by Anonymous Monk on Oct 09, 2009 at 10:24 UTC
    %s/#1/# 1/g
Re: (OT) Regular Expression
by Gangabass (Vicar) on Oct 09, 2009 at 12:23 UTC

    I think you need something like:

    %s/^#1/#\r1/g
Re: (OT) Regular Expression
by Anonymous Monk on Oct 09, 2009 at 09:23 UTC
    vi has perl regular expressions?
      Hi!
      vi has perl regular expressions?
      If you compile vim with perl support, you can directly execute perl commands inside vim

      see also: http://vimdoc.sourceforge.net/htmldoc/if_perl.html

      Have fun!

      Update Your command would be:

      :perldo $_ =~ s/#1/# 1/g;
      with :perldo executing the given command on each line of your file.
Re: (OT) Regular Expression
by mickep76 (Beadle) on Oct 09, 2009 at 09:07 UTC

    You could simply do:

    $test = '#1 aba baba'; $test =~ s/#1/# 1/g; print "$test\n";