The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Named PIPE Tamil UNIX for Dummies Questions & Answers 2 01-17-2007 12:20 AM
using pipe in a loop netman High Level Programming 3 01-04-2006 11:30 PM
Truncated with a pipe? TheCrunge Shell Programming and Scripting 1 11-14-2005 03:35 PM
PIpe Spy jodders High Level Programming 11 02-18-2004 07:44 AM
pipe help bb666 High Level Programming 5 02-26-2002 01:07 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-01-2008
Registered User
 

Join Date: Jul 2008
Posts: 34
need help to put pipe(|) in between characters

Hi,

I need to put | bet ween every 3 characters in a string.

InString = abcd12342
Out = abc|d12|342

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 10-01-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
if you have PHP
Code:
# printf "abcd12342" | php5 -r 'echo implode("|",(str_split(file_get_contents("php://stdin"),3)));'
abc|d12|342
Reply With Quote
  #3  
Old 10-01-2008
Registered User
 

Join Date: Feb 2006
Location: Canada
Posts: 23
for Perl, you can use this if you're going from and to files:
Code:
#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl

local $/ = \3 ;

open (FILE,"in.txt");
while(<FILE>) {
$out .= $_ . "|";
}
close (FILE);

open (FILE,">out.txt");
print FILE "$out";
close (FILE);

exit;
Reply With Quote
  #4  
Old 10-01-2008
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Try...
Code:
$ echo abcd12342 | fold -3 | paste -s -d '|'
abc|d12|342
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0