removing \n and get a new line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pavanponnapalli
    New Member
    • May 2008
    • 51

    removing \n and get a new line

    hi,
    I have got a text as under:
    he is a good boy \n he works hard \n and he plays well \n

    I need to remove the \n in the text and get a newline instead. How is it possible using regular expressions?
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    Use search and replace option: s///
    Code:
    s/\\n/\n/g;
    For ex. if you are reading from a file and substitute '\n' in each line with newline(\n)
    Code:
    open(F,"data.txt") or die "$!";
    while(<F>) {
      s/\\n/\n/g;
       print $_;
    }
    Last edited by nithinpes; Jun 5 '08, 12:15 PM. Reason: edited tags

    Comment

    • pavanponnapalli
      New Member
      • May 2008
      • 51

      #3
      Originally posted by nithinpes
      Use search and replace option: s///
      Code:
      s/\\n/\n/g;
      For ex. if you are reading from a file and substitute '\n' in each line with newline(\n)
      Code:
      open(F,"data.txt") or die "$!";
      while(<F>) {
        s/\\n/\n/g;
         print $_;
      }
      Hi friend,
      Thank you very much for ur nice reply.

      cheers,
      pavan

      Comment

      Working...