1

I have a property file in which a particular key has comma delimited values.

$cat sample.prorerties

value=alex,raj,kaly,rema

In my shell script I implement this property file and use the key value to get its values.

...
. sample.properties
echo $value
...

here is what I get as output

$ alex,raj,kaly,rema

However I am looking for a space delimited value like this

alex raj kaly rema

I know how to do this for a file however I am not certain about something which is assigned to a variable. Any help is much appreciated.

1
  • 2
    Incidentally: spelling: prorerties -> properties
    – Wildcard
    Commented Nov 8, 2016 at 10:24

2 Answers 2

6

You can use Bash string manipulation:

value=alex,raj,kaly,rema
echo $value 
alex,raj,kaly,rema

Now replace all , with ' ' (space):

echo ${value//,/ }
alex raj kaly rema

bash --version
GNU bash, version 3.2.57(1)-release
2

You can try the tr command.

Here's the script:

#!/bin/bash
value=alex,raj,kaly,rema
echo $value | tr ',' ' '

Here's the output:

bash bash.sh 
alex raj kaly rema

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .