Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Tue Jun 06, 2023 7:54 am


Tips & Tricks, Questions regarding shell scripts, awk, perl, sed and much more.

Author Message
mandrei99
Post  Post subject: How to replace new line in perl script  |  Posted: Wed Jun 26, 2013 8:03 am

Joined: Tue Aug 04, 2009 9:16 am
Posts: 250

Offline
 

How to replace new line in perl script

In previous article, I showed how to use Linux shell to echo new line. I'm going to use that example for this post.


Echoing multiple new lines:
Code:
# echo -e "text\n\n\n"
text



#


Let's say we send this output to a perl script via pipe:
Code:
# echo -e "text\n\n\n" | perl /tmp/perl-new-line.pl   
text#
# cat /tmp/perl-new-line.pl
#!/usr/bin/perl
while(<>){
  $_ =~ s/\n//;
  print "$_";
}


The script takes the input and parses every line with new line characters at the end of it. Then for each line, it removes the new line and echoes the result.





Top
admin
Post  Post subject: Re: How to replace new line in perl script  |  Posted: Wed Jun 26, 2013 8:18 am
Site Admin

Joined: Mon Aug 03, 2009 8:43 am
Posts: 104

Offline
Or directly via shell command line.
Code:
# echo -e "asfd\n\n\n" | perl -pe 's/\n\r?/,/'   
asfd,,,,#

_________________
VPSie - SSD VPS servers in AMS-IX, LINX, DE-CIX
https://vpsie.com


Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "How to replace new line in perl script"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Removing new line / EoL characters in a PERL script

mandrei99

0

4405

Mon Nov 04, 2013 6:47 am

mandrei99 View the latest post

There are no new unread posts for this topic. PERL: How to replace non-ascii characters/bytes in a file

admin

0

3372

Fri Apr 10, 2015 8:58 am

admin View the latest post

There are no new unread posts for this topic. Attachment(s) Juniper SRX - Perl script - SNMP based RRDtool graphis from CPU usage and Flow Session (current)

mandrei99

1

5960

Mon Nov 04, 2013 11:47 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to replace \w SED multiple matches on the same line without piping

mandrei99

0

3448

Tue Oct 08, 2013 6:29 am

mandrei99 View the latest post

There are no new unread posts for this topic. Echo new line in linux - supress new line or echo multiple new lines

mandrei99

0

6020

Wed Jan 14, 2015 5:26 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to replace dot or any character with AWK

mandrei99

0

15893

Tue Jan 28, 2014 6:35 am

mandrei99 View the latest post

There are no new unread posts for this topic. AWK: How to replace a newline with actual \n

admin

0

2504

Thu Jul 20, 2017 11:02 am

admin View the latest post

There are no new unread posts for this topic. Unix shell - using TR to replace new lines with spaces

debuser

0

8832

Thu Feb 25, 2010 8:08 am

debuser View the latest post

There are no new unread posts for this topic. SED uncomment line - How to uncomment a line or all lines with SED

mandrei99

0

7766

Wed Jan 14, 2015 5:08 pm

mandrei99 View the latest post

There are no new unread posts for this topic. Password generator with user inputs bash script

Kvr123

0

2302

Thu Dec 01, 2016 5:06 am

Kvr123 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO