my problem of today is to replace in a string like this --> 6427//6422 6429//6423 6428//6421
every //
with a ,
. I tried with different commands:
finalString=${startingString//[//]/,}
doesn't workfileTemp=$(echo -e "$line\n" | tr "//" ","
does a double substitution like this:
hello//world
---> hello,,world
Someone has an idea of a way to do it?
You can use BASH string manipulations (need to escape /
with \/
):
s='6427//6422 6429//6423 6428//6421'
echo "${s//\/\//,}"
6427,6422 6429,6423 6428,6421
Similarly using awk:
awk -F '//' -v OFS=, '{$1=$1}1' <<< "$s"
6427,6422 6429,6423 6428,6421
PS: tr
cannot be used here since tr
translates each character in input to another character in the output and here you're dealing with 2 characters //
.
You can use sed as
$ echo "6427//6422 6429//6423 6428//6421" | sed 's#//#,#g'
6427,6422 6429,6423 6428,6421
You can also try the sed command like this
sed 's#/\{2,2\}#,#g'
finds double "/" and replace with ","
Example
echo "6427//6422 6429//6423 6428//6421"| sed 's#/\{2,2\}#,#g'
Results
6427,6422 6429,6423 6428,6421
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With