![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
"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
|
|
#3
|
||||
|
||||
|
#4
|
|||
|
|||
|
|
|
#5
|
|||
|
|||
|
Hello:
so what are the hash and the question marks for in : Code:
rest=${string#?????}
piece1=${string%$rest}
|
|
#6
|
|||
|
|||
|
Quote:
? Matches single character rest=${string#?????} Removes the first five characters |
|
#7
|
|||
|
|||
|
THX alot anbu23
|
|||
| Google The UNIX and Linux Forums |