LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Removing Text from a Shell String (https://www.linuxquestions.org/questions/programming-9/removing-text-from-a-shell-string-171560/)

OrangeLefty 04-18-2004 04:05 AM

Removing Text from a Shell String
 
Hey,

Ive got a very simple question. I have a small script that has a varaible ( $mapfile ) that will return something like foo.map (can be also foobar.map, buzzle.map, shodown.map, blah.map, you get the point)

Now how do i get it to remove the .map part? Perferably by setting a new variable so i dont mess anything currently in the script.

Thanks a bunch.

Hko 04-18-2004 05:24 AM

nomapfile=${mapfile%.map}

e.g.
Code:

#!/bin/sh

files="foofoo.map barbar.map thing.map foobar.map barfoo.map"

for mapfile in $files ; do
        nomapfile=${mapfile%.map}
        othfile=${nomapfile}.oth
        echo -e "$mapfile\t\t$nomapfile\t\t$othfile"
done


OrangeLefty 04-18-2004 11:08 PM

Thank you very much, it worked without any problems :)


All times are GMT -5. The time now is 05:06 AM.