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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-29-2001
mexx_freedom mexx_freedom is offline
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
  #2 (permalink)  
Old 08-29-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
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
Optimus_P Optimus_P is offline Forum Advisor  
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
mexx_freedom mexx_freedom is offline
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
  #5 (permalink)  
Old 08-30-2001
Optimus_P Optimus_P is offline Forum Advisor  
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-31-2001
mexx_freedom mexx_freedom is offline
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
  #7 (permalink)  
Old 08-31-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,128
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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0