By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,807 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,807 IT Pros & Developers. It's quick & easy.

removing \n and get a new line

P: 51
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?
Jun 5 '08 #1
Share this Question
Share on Google+
2 Replies


nithinpes
Expert 100+
P: 410
Use search and replace option: s///
Expand|Select|Wrap|Line Numbers
  1. s/\\n/\n/g;
  2.  
For ex. if you are reading from a file and substitute '\n' in each line with newline(\n)
Expand|Select|Wrap|Line Numbers
  1. open(F,"data.txt") or die "$!";
  2. while(<F>) {
  3.   s/\\n/\n/g;
  4.    print $_;
  5. }
  6.  
Jun 5 '08 #2

P: 51
Use search and replace option: s///
Expand|Select|Wrap|Line Numbers
  1. s/\\n/\n/g;
  2.  
For ex. if you are reading from a file and substitute '\n' in each line with newline(\n)
Expand|Select|Wrap|Line Numbers
  1. open(F,"data.txt") or die "$!";
  2. while(<F>) {
  3.   s/\\n/\n/g;
  4.    print $_;
  5. }
  6.  
Hi friend,
Thank you very much for ur nice reply.

cheers,
pavan
Jun 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.