The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
from - to delimiter bighippo Shell Programming and Scripting 6 03-12-2008 11:47 PM
Charater comparison Tornado Shell Programming and Scripting 4 01-10-2008 10:01 PM
\r as delimiter in cut shweta_d Shell Programming and Scripting 5 06-07-2007 06:18 AM
running an Acii charater in a script. quispiam Shell Programming and Scripting 4 08-25-2004 05:03 AM
replacing charater odogbolu98 Shell Programming and Scripting 3 05-28-2002 12:18 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-10-2007
Registered User
 

Join Date: Jul 2007
Posts: 21
Inserting a delimiter after certain charater position

Hi,
I have a string : -
ICFFHASMTAAMPFINCL22082006000002548789632
and i want to add delimiter after certain charater position through a script, eg. ICFFH,ASMTAAMPF,INCL,22082006,000002548789632.

I have tried and am able to achieve it through cut-paste. But i don't want to use cut paste as it is taking up a lot of space.

Can you please suggest any another way to do this?
Reply With Quote
Forum Sponsor
  #2  
Old 07-10-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,620
"taking up a lot of space"? I don't know what that is supposed to mean, but here is a very fast technique....
Code:
#! /usr/bin/ksh

string="ICFFHASMTAAMPFINCL22082006000002548789632"
echo "$string"

rest=${string#?????}
piece1=${string%$rest}
string=$rest

rest=${string#?????????}
piece2=${string%$rest}
string=$rest

rest=${string#????}
piece3=${string%$rest}
string=$rest

piece5=${string#????????}
piece4=${string%$piece5}

string2="${piece1},${piece2},${piece3},${piece4},${piece5}"

echo $string2
exit 0
Reply With Quote
  #3  
Old 07-10-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
See similar http://www.unix.com/shell-programmin...-a-record.html
Reply With Quote
  #4  
Old 07-10-2007
Registered User
 

Join Date: Jul 2007
Posts: 21
Thanks a lot. It works!!!
Reply With Quote
  #5  
Old 07-11-2007
Registered User
 

Join Date: Oct 2006
Posts: 78
Hello:
so what are the hash and the question marks for in :

Code:
rest=${string#?????}
piece1=${string%$rest}
Reply With Quote
  #6  
Old 07-11-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by aladdin View Post
Hello:
so what are the hash and the question marks for in :

Code:
rest=${string#?????}
piece1=${string%$rest}
${string#substring} Strips shortest match of $substring from front of $string.
? Matches single character
rest=${string#?????} Removes the first five characters
Reply With Quote
  #7  
Old 07-11-2007
Registered User
 

Join Date: Oct 2006
Posts: 78
THX alot anbu23
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:03 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