Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

append two pipes ('|') 2

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
I have a file that conatains roughly 700,000 records. I need a quick way to append two pipe characters to the end of each record. So, If input looks like this:

aaa|bbb|ccc
aaaa|bbbb|cccc
nnnnnnnnnnnnnnnnn

Output needs to look like this:

aaa|bbb|ccc||
aaaa|bbbb|cccc||
nnnnnnnnnnnnnnnnn||

Anyone know how to do this, quickly? I wrote a .ksh script, but it's pretty slow. Maybe use awk or sed? Anyone?
 
The sed way:
sed 's!$!||!' /path/to/input >output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
well, it does have 700,000 records, so slow is a relative term, lol

Code:
#!/usr/local/bin/perl -w
use strict;

my $filename = "/path/to/filename";
my $outputfile = "/where/to/put/the/output";
open(INFILE "< $filename");
open(OUTFILE "> $outputfile");

while(<INFILE>){

printf(OUTFILE, "%s\|\|\n",$_);
}
close INFILE;
close OUTFILE;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top