467,179 Members | 1,333 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

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?
Jun 5 '08 #1
  • viewed: 1187
Share:
2 Replies
nithinpes
Expert 256MB
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
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.

Similar topics

16 posts views Thread by qwweeeit | last post: by
1 post views Thread by ChrisC | last post: by
5 posts views Thread by nuffnough@gmail.com | last post: by
3 posts views Thread by Kilicaslan Fatih | last post: by
17 posts views Thread by Eric_Dexter@msn.com | last post: by
m6s
3 posts views Thread by m6s | last post: by
reply views Thread by Adam Salisbury | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.