Issue
{"date":"12:44", <-----Need to keep the second colon in this line only "temp":"38.6", "tempTL":"38.6", "tempTH":"46.9", "intemp":"66.6", "dew":"36.8", "dewpointTL":"36.8", "dewpointTH":"46.9",
#!/bin/bash
# Script to upload files.
# Delete current file
rm /home/pi/allsky/realtimegauges.txt
# Get weather text file from web
wget https://www.melvinweather.com/realtimegauges.txt
# Change permissions of text file
chmod 777 realtimegauges.txt
#Replace { with nothing
sed -i 's/{//g' realtimegauges.txt
#Replacedate with time
sed -i 's/date/time/g' realtimegauges.txt
#replace the " with nothing
sed -i 's/"//g' realtimegauges.txt
# replace the : with = sign.
sed -i 's/:/=/g' realtimegauges.txt
#Remove the trailing ,
sed -i 's/,//g' realtimegauges.txt
# Copy file to the allsky/tmp/extra/
cp realtimegauges.txt /home/pi/allsky/tmp/extra
I end up with time=xx=xx I need to end up with time=00:00
Solution
The command you have:
sed -i 's/:/=/g' realtimegauges.txt
The option g
means that it will replace all matches in each line. If instead you only need it to replace a specific one, in this case only the first match, you can do so:
sed -i 's/:/=/1' realtimegauges.txt
Which will replace only the first match in each line.
Answered By - M. Becerra Answer Checked By - Marilyn (WPSolving Volunteer)