View previous topic :: View next topic |
Author |
Message |
EnlightedGnome Tux's lil' helper
Joined: 07 Jun 2005 Posts: 126 Location: Denmark, Odense
|
Posted: Thu Jul 21, 2005 10:51 pm Post subject: How to remove one string from another? [solved] |
|
|
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 |
|
|
spb Retired Dev
Joined: 02 Jan 2004 Posts: 2135 Location: Cambridge, UK
|
Posted: Thu Jul 21, 2005 11:13 pm Post subject: |
|
|
sed. |
|
Back to top |
|
|
platojones Veteran
Joined: 23 Oct 2002 Posts: 1602 Location: Just over the horizon
|
|
Back to top |
|
|
EnlightedGnome Tux's lil' helper
Joined: 07 Jun 2005 Posts: 126 Location: Denmark, Odense
|
Posted: Fri Jul 22, 2005 10:49 am Post subject: |
|
|
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 |
|
|
platojones Veteran
Joined: 23 Oct 2002 Posts: 1602 Location: Just over the horizon
|
Posted: Fri Jul 22, 2005 11:15 am Post subject: |
|
|
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 |
|
|
void81 n00b
Joined: 17 Jan 2005 Posts: 23 Location: Germany (Dortmund)
|
|
Back to top |
|
|
limn l33t
Joined: 13 May 2005 Posts: 997
|
Posted: Fri Jul 22, 2005 12:09 pm Post subject: |
|
|
platojones wrote: |
echo "${STR/SUBSTR/REPL}"
|
Try instead:
Code: | echo "${STR/$SUBSTR/$REPL}" |
|
|
Back to top |
|
|
platojones Veteran
Joined: 23 Oct 2002 Posts: 1602 Location: Just over the horizon
|
Posted: Fri Jul 22, 2005 10:23 pm Post subject: |
|
|
Thanks limn, right you are. Been a while since I used those, but they are nice to have. |
|
Back to top |
|
|
|