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 > 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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed xml challenge katrvu Shell Programming and Scripting 2 04-10-2008 07:50 PM
AWK Challenge netmedic Shell Programming and Scripting 9 02-18-2008 04:08 AM
camma challenge (in ksh) Amresh Dubey Shell Programming and Scripting 3 10-31-2007 05:10 AM
A challenge for you sed/awk wizards... th3g0bl1n UNIX for Dummies Questions & Answers 2 10-24-2007 10:37 AM
safeword challenge blowtorch UNIX for Advanced & Expert Users 2 10-10-2006 10:44 PM

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 04-07-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
sed replacement, challenge one!!!!

Hi all,

Thanks in advanced.

This question really bothered me much. What i want is to replace any times of repeated 'TB' to 'T', below is example.
It can be fullfil by AWK and perl, but my desire is using SED to realize it.

So here means we treat TB as a whole part, which means 's/TB*/T/' and
's/[TB]*/t/' can not fullfill it.

Code:
aTBb              -> aTb
aTBTBc           -> aTc
aTBTBTBd        -> aTd
aTBTTBTBe      -> aTBTTBTBe
  #2 (permalink)  
Old 04-07-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,924
Maybe it is too early in the morning but what is different about the last line i.e. 'aTBTTBTBe' ? It has the pattern 'TB' in it. Surely it should change to 'aTTTe"
  #3 (permalink)  
Old 04-07-2008
V3l0 V3l0 is offline
Registered User
  
 

Join Date: Nov 2007
Location: Belgium & France
Posts: 70
Try this:
File atd
Code:
#!/bin/ksh

for i in $*
do
        z=$(echo $i | grep TT)
        if [ x"$z" = x ]
        then
                z=$(echo $i | sed -e 's/TB/T/g')
                while [ 1 ]
                do
                        z=$(echo $z | sed -e 's/TT/T/g')
                        if [ x"$(echo $z | grep TT)" = x ]
                        then
                                break
                        fi
                done
                echo $i/$z
        else
                echo $i/$i
        fi
done
Run it:
Code:
./atd aTBb aTBTBc aTBTBTBd aTBTTBTe
aTBb/aTb
aTBTBc/aTc
aTBTBTBd/aTd
aTBTTBTe/aTBTTBTe
  #4 (permalink)  
Old 04-07-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Hi,

How about the below one,

Code:
sed 's/TT/#T#T/g;s/BB/#B#B/g;/#/!s/TB.*TB/T/g;/#/!s/TB/T/g;s/#//g' inp.txt
does it help?

Regards,
Chella
  #5 (permalink)  
Old 04-07-2008
V3l0 V3l0 is offline
Registered User
  
 

Join Date: Nov 2007
Location: Belgium & France
Posts: 70
NICE !!!

Quote:
Originally Posted by chella View Post
Hi,

How about the below one,

Code:
sed 's/TT/#T#T/g;s/BB/#B#B/g;/#/!s/TB.*TB/T/g;/#/!s/TB/T/g;s/#//g' inp.txt
does it help?

Regards,
Chella
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 12:38 AM.


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