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.