Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to remove one string from another? [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
EnlightedGnome
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jun 2005
Posts: 126
Location: Denmark, Odense

PostPosted: Thu Jul 21, 2005 10:51 pm    Post subject: How to remove one string from another? [solved] Reply with quote

Is there some kind of tool like tr, but working with entire strings and not just single chars?
_________________
checking for -lifesign in -Kenny... no
- oh my god, they killed Kenny


Last edited by EnlightedGnome on Wed Aug 10, 2005 1:05 am; edited 1 time in total
Back to top
View user's profile Send private message
spb
Retired Dev
Retired Dev


Joined: 02 Jan 2004
Posts: 2135
Location: Cambridge, UK

PostPosted: Thu Jul 21, 2005 11:13 pm    Post subject: Reply with quote

sed.
Back to top
View user's profile Send private message
platojones
Veteran
Veteran


Joined: 23 Oct 2002
Posts: 1602
Location: Just over the horizon

PostPosted: Thu Jul 21, 2005 11:23 pm    Post subject: Reply with quote

Bash, of course, can do this as well. Have a look at "String Operators" on this page:

http://www.tldp.org/LDP/abs/html/refcards.html#AEN16857

Of course sed is very popular and so is awk.
Back to top
View user's profile Send private message
EnlightedGnome
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jun 2005
Posts: 126
Location: Denmark, Odense

PostPosted: Fri Jul 22, 2005 10:49 am    Post subject: Reply with quote

Can you give me an exampel? With eighter sed or bash.
_________________
checking for -lifesign in -Kenny... no
- oh my god, they killed Kenny
Back to top
View user's profile Send private message
platojones
Veteran
Veteran


Joined: 23 Oct 2002
Posts: 1602
Location: Just over the horizon

PostPosted: Fri Jul 22, 2005 11:15 am    Post subject: Reply with quote

With bash:

STR="abcdefg"
SUBSTR="efg"
REPL="xyz"
echo "${STR/SUBSTR/REPL}"

abcdxyz

With sed:

echo "abcdefg" | sed 's/efg/xyz/'

abcdxyz

UPDATE: Hrmmm, the bash example doesn't work. It used too. Forget that and use sed.


Last edited by platojones on Fri Jul 22, 2005 11:28 am; edited 1 time in total
Back to top
View user's profile Send private message
void81
n00b
n00b


Joined: 17 Jan 2005
Posts: 23
Location: Germany (Dortmund)

PostPosted: Fri Jul 22, 2005 11:22 am    Post subject: Reply with quote

Nice link with examples for sed.

http://main.rtfiber.com.tw/~changyj/sed/
Back to top
View user's profile Send private message
limn
l33t
l33t


Joined: 13 May 2005
Posts: 997

PostPosted: Fri Jul 22, 2005 12:09 pm    Post subject: Reply with quote

platojones wrote:

echo "${STR/SUBSTR/REPL}"

Try instead:
Code:
echo "${STR/$SUBSTR/$REPL}"
Back to top
View user's profile Send private message
platojones
Veteran
Veteran


Joined: 23 Oct 2002
Posts: 1602
Location: Just over the horizon

PostPosted: Fri Jul 22, 2005 10:23 pm    Post subject: Reply with quote

Thanks limn, right you are. Been a while since I used those, but they are nice to have.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum