![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
|
||||
|
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, |
|
||||
|
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 |
|
||||
|
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, |
|
||||
|
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 | ||
|
|