PDA

View Full Version : sh replace string


killasmurf86
07-24-2008, 07:14 PM
Let's say i have some input data
$DATA="Some text data that i want to change"

and i want to replace spaces with some other letter, lets say "_"
How can i do that in sh?

ephemera
07-24-2008, 07:35 PM
DATA='Some text data that i want to change'
DATA=$(echo $DATA | tr ' ' _)

phoenix
07-24-2008, 07:37 PM
DATA="Some text data that i want to change"
DATA=$( echo $DATA | sed 's|text data|binary crap|' )
echo $DATA

Sorry, didn't see you wanted to just switch one character. tr is best for that.