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
grep patterns - File dhanamurthy Shell Programming and Scripting 1 05-08-2008 07:24 PM
How to cut multiple patterns from a file? Vijay06 Shell Programming and Scripting 5 11-26-2007 05:38 PM
How to replace the string in unix file? param_it UNIX for Dummies Questions & Answers 5 06-26-2007 06:06 AM
c++, design patterns and Unix mihk High Level Programming 3 04-25-2007 11:02 PM
replace delimiter : with '\001' in unix data file spandu Shell Programming and Scripting 4 04-25-2006 05:51 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2001
Registered User
 

Join Date: Jul 2001
Location: Bangalore,India
Posts: 7
Question how to replace certain patterns in a file thru unix!!

Hi Friends,
well what i want to do is that suppose i have a file say like
....
ronaldduckdancecoolman
donaldmuckdancepooltactics
fonaldguckdancetoolbutcomps
....
okok i agree this is a ridiculous data for a file.
:-)
now i want that the characters in each line fromposition 16 to say 19 gets replaced by a particular string , in this case the charcters are cool pool and tool , so say i want is the follwoing output:

....
ronaldduckdanceYYYYman
donaldmuckdanceYYYYtactics
fonaldguckdanceYYYYbutcomps
....

or maybe it is possible that the case is that i want to replcae cool,tool and pool by word whose length is greate than the ones which are present say like

....
ronaldduckdanceYYYYYYYYman
donaldmuckdanceYYYYYYYYtactics
fonaldguckdanceYYYYYYYYbutcomps
....

and also suppose i want say that a particular word occurence in every line is replaced by some other word say like i have input file containing

....
ronaldduckdanceYYYYman
donaldmuckdanceYYYYtactics
fonaldguckdanceYYYYbutcomps
....

and i want the file to be manipulated as
....
ronaldduckdanceXXXXman
donaldmuckdanceXXXXtactics
fonaldguckdanceXXXXbutcomps
....

or say different lengths replacement like
....
ronaldduckdanceXXXXXXXXman
donaldmuckdanceXXXXXXXXtactics
fonaldguckdanceXXXXXXXXbutcomps
....

the bottomline being that there r 2 cases one being replacement being on base of position and the other being replaxcement on basis of certain pattern.

HOW do i do this????
PLzzz help

Regards
Manish
__________________
Manish Joneja
Forum Sponsor
  #2 (permalink)  
Old 08-29-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
pattern replacement

Sounds like you need "sed".
Check out...
http://wwwinfo.cern.ch/dis/texi2html...2/sed_toc.html
  #3 (permalink)  
Old 08-29-2001
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
aye sed does soudn liek the way you want to go.

sed 's/.ool/&ltreplacement string&gt/'
  #4 (permalink)  
Old 08-30-2001
Registered User
 

Join Date: Jul 2001
Location: Bangalore,India
Posts: 7
Hi,
Thanks a lot pals , one of the problems is solved but still one exists.
i am unable to replace based on positions,
could u shed some light on that part plzzzz.
Regards
Manish
__________________
Manish Joneja
  #5 (permalink)  
Old 08-30-2001
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
you will want to look into sed. we gave you the key to open the door. you just have to turn the knob.

you will want to look into regular exprestions also.
  #6 (permalink)  
Old 08-30-2001
Registered User
 

Join Date: Jul 2001
Location: Bangalore,India
Posts: 7
Unhappy

Hi optimus,
i turned the knob!
looked in regular expresions too, but all i cud find is pattern replacement but noting on positional replacement!
Help if u can plzzz.
Regards
Manish
__________________
Manish Joneja
  #7 (permalink)  
Old 08-31-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,352
A few patterns to experiment with:

Some hints:
Code:
. is any character
......  is any 6 characters
.\{6\}  also any 6 characters
\(.\{6\}\) any 6 characters saved as subexpression
^\(.\{6\}\) first 6 characters saved as subexpression
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:52 AM.


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

Content Relevant URLs by vBSEO 3.2.0