![]() |
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 |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
Code:
./atd aTBb aTBTBc aTBTBTBd aTBTTBTe aTBb/aTb aTBTBc/aTc aTBTBTBd/aTd aTBTTBTe/aTBTTBTe |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|