![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| rm substitute with blacklist | broli | UNIX for Dummies Questions & Answers | 2 | 12-06-2007 05:13 AM |
| Substitute File name | vanand420 | Shell Programming and Scripting | 22 | 03-13-2007 11:40 PM |
| Substitute in vi | kingdbag | UNIX for Dummies Questions & Answers | 5 | 01-17-2007 11:42 AM |
| how to substitute more than one word in a text file? | forevercalz | Shell Programming and Scripting | 2 | 01-12-2006 03:32 AM |
| vi + regexp + substitute | Lomic | UNIX for Dummies Questions & Answers | 9 | 12-10-2004 07:50 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
In Help, Substitute Text ...
i'm writing a script that will extract and substitute a certain part of a data.
i'm having trouble with the substituting part ... Here's my data looks like: 01/01/08-001-23:46:18-01/01/08-23:50:43 01/01/08-003-23:45:19-01/01/08-23:55:49 01/01/08-005-23:52:18-01/01/08-23:58:52 i want to change the second column i.e. 001,003,005 to: CODE01 for 001, CODE03 for 003 and CODE05 for 005. so that it will look like this ... 01/01/08-CODE01-23:46:18-01/01/08-23:50:43 01/01/08-CODE03-23:45:19-01/01/08-23:55:49 01/01/08-CODE05-23:52:18-01/01/08-23:58:52 i have separate a file for the list of codes to be substituted. i tried using sed, but can't figure out how. i'm on: using csh SunOS 5.8 Generic_108528-22 sun4u sparc SUNW,UltraAX-MP oh btw, im new here =D |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
nawk -F- -v OFS=- '$2=sprintf("CODE%02d", $2); print' myFile.txt
|
|
#3
|
|||
|
|||
|
@vgersh99
Thanks ... just a follow up, i have another database, but with different codes i.e. 001=red,003=blue,005=orange. any suggestion? i tried playing with your code, but no useful results happened. i'm still newbie in this csh thing ... |
|
#4
|
|||
|
|||
|
How many CODE's you have ..I mean is the number of CODEs finite
|
|
#5
|
|||
|
|||
|
finite number of codes
|
|
#6
|
|||
|
|||
|
This works in bash
$ cat a.a
01/01/08-001-23:46:18-01/01/08-23:50:43 01/01/08-003-23:45:19-01/01/08-23:55:49 01/01/08-005-23:52:18-01/01/08-23:58:52 $ sed 's/-00\([0-9]\)-/-CODE0\1-/' a.a > b.b $ cat b.b 01/01/08-CODE01-23:46:18-01/01/08-23:50:43 01/01/08-CODE03-23:45:19-01/01/08-23:55:49 01/01/08-CODE05-23:52:18-01/01/08-23:58:52 |
|
#7
|
||||
|
||||
|
what's the format of the 'code' to 'color' mapping? Sample, pls!
|
||||
| Google The UNIX and Linux Forums |