The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
need assistance: sed and repeating patterns metalwarrior UNIX for Advanced & Expert Users 1 02-02-2008 05:00 AM
Repeating variables in the code mahalakshmi Shell Programming and Scripting 1 02-08-2007 07:33 AM
Repeating commands in a script Dave2874 Shell Programming and Scripting 4 03-14-2005 10:34 AM
Omit repeating lines TheCrunge UNIX for Dummies Questions & Answers 6 02-22-2005 06:26 PM
repeating kernel message progressdll UNIX for Advanced & Expert Users 2 07-29-2002 04:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-02-2008
metalwarrior metalwarrior is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
assitance with sed (repeating patterns)

hi,
I need to write a command to look into a text file, find lines that contain patterns of three or more characters that repeat once, and put perenthesizes around them. so for example, the line "123test123" would be changed to "(123)test(123)" and "abcdeabcde" to "(abcde)(abcde)".
any hint is appreciated.
  #2 (permalink)  
Old 02-02-2008
Prahlad Prahlad is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 11
Hello,

I can help you with 1st query , where you are trying to change "123test123" to "(123)test(123)" .

This can be done easily using SED .

----------
Syntax: sed -e 's/\(123\)/(\1)/g' :--> g parameter will replace the instance globally in file.

Example: echo 123test123 | sed -e 's/\(123\)/(\1)/g'
Output : (123)test(123)
----------

Try this out in your file and let us know how it goes at your end.

Thanks,
  #3 (permalink)  
Old 02-02-2008
metalwarrior metalwarrior is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
hi thanks for the reply, but I need the sed command to find all repeating patterns itself and put them inside (). I can not specify the pattern for it to look for.
it can be 123 or abc or anything that is repeated through the line.
thank you
  #4 (permalink)  
Old 02-02-2008
Prahlad Prahlad is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 11
Hello Metalwarrior,

Do you have any sigle pattern to replace ?

Or any patter which contains 3 or more than characters ?

Thanks,
  #5 (permalink)  
Old 02-02-2008
metalwarrior metalwarrior is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
ok let's say I have this line for example:
thispatternthatpattern
I want the sed automatically find the the repeated patterns and put them in (). so after the chagne it would look like this,
this(pattern)that(pattern).
  #6 (permalink)  
Old 02-02-2008
Prahlad Prahlad is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 11
If you have only one or limited patter to replace then it can be done easily with sed as explained earlier.

Please follow the steps.

--------
1) Save thispatternthatpattern in a file called test
2) Now according to you thispatternthatpattern should be converted to this(pattern)that(pattern) .
3) Now type following command
----------
sed -i 's/patter/(pattern)/g' test
-----------

4) See the o/p using "cat test". It should be as pasted below.

bash-3.1$ cat test
this(pattern)nthat(pattern)n

--------

Thanks,
  #7 (permalink)  
Old 02-02-2008
metalwarrior metalwarrior is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
hi tnx but that's not what I am looking for.
like I said I dont want to specify then pattern for sed.
I want it automatically find all the patterns that are repeated and do something with them. the regular expression would be something like this:
'.*\{3,\}\.*\1'
but I can only save the whole thing into register1, I cant distinguish between the first pattern, repeated pattern and possible contents between them.
Sponsored Links
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 03:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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