The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

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

Join Date: Feb 2008
Location: Philippines
Posts: 6
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
Reply With Quote
Forum Sponsor
  #2  
Old 02-06-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
Code:
nawk -F- -v OFS=- '$2=sprintf("CODE%02d", $2); print'  myFile.txt
Reply With Quote
  #3  
Old 02-06-2008
Registered User
 

Join Date: Feb 2008
Location: Philippines
Posts: 6
@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 ...
Reply With Quote
  #4  
Old 02-06-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
How many CODE's you have ..I mean is the number of CODEs finite
Reply With Quote
  #5  
Old 02-06-2008
Registered User
 

Join Date: Feb 2008
Location: Philippines
Posts: 6
finite number of codes
Reply With Quote
  #6  
Old 02-06-2008
Registered User
 

Join Date: Aug 2007
Posts: 16
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
Reply With Quote
  #7  
Old 02-07-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
Quote:
Originally Posted by solidhelix08 View Post
@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 ...
what's the format of the 'code' to 'color' mapping? Sample, pls!
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 02:06 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