Adding a PIPE delimiter at end of line

Posted on 2000-04-04
Last Modified: 2012-08-13
I already have parsed a file and delimited it with PIPE (|) --- except after the last field.
Is there a way I can add the PIPE  (|) delimeter at the end of the line without doing the whole thing again? I need some sort of global pattern search and add or update feature.
Question by:tgbekele
  • 2
  • 2
LVL 16

Expert Comment

ID: 2684805
you can use the \n char as your reference, since \n indicates end of line. Basically search for \n and replace it with a | and \n

lets say each line of your file is stored in a var called $var.
$var is in a loop.

open(FILE,"the_piped_file") || die $!;
while $var(<FILE>){
$var=~ s/\n/\|\n/;


Author Comment

ID: 2684883

thank you ... works great as long as the last column in the data is not blank ... for those lines that have a blank space, it is not placing the |.
Any ideas why?
LVL 84

Expert Comment

ID: 2684891
{local $^I=''; local @ARGV=('the_piped_file');
  while( <> ){ s/$/|/; print }
LVL 16

Accepted Solution

maneshr earned 50 total points
ID: 2685136

$var=~ s/\n/\|\n/;

$var=~ s/$/\|/;

and that will be solved too...

Author Comment

ID: 2685207
Thank you very much ... that worked!!!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Passing shell scripts to run on the SFTP cmd object 12 180
HTTP Error 502.2 - Bad Gateway 3 205
Perl Sort Question 4 129
Which version of C should I use when Perl is too slow? 13 173
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now