| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
On 16/09/17 10:40, Michelle Konzack [email protected] [sed-users]
wrote:
> Good day,
>
> I have seleral 1000 records of wind/solar data which where inserted in a
> HTML page manually and it looks like:
>
> <TR class="table_energy_row">
> <TD class="energytable_num" >1</TD>
> <TD class="energytable_date" >2017-07-23 Sat</TD>
> <TD class="energytable_time" >23:59</TD>
> <TD class="energytable_wh_solar">1387</TD>
> <TD class="energytable_wh_wind" >0</TD>
> <TD class="energytable_comment" >Absolutely no wind the last 18 hours.<BR>Solarcharger went into FLOAT, because the battery was full.</TD>
> </TR>
>
> So, I made a script and now my records look like
>
> <?php
> $date = "2017-07-23";
> $time = "23:59";
> $wh_solar = "1387";
> $wh_wind = "0";
> $comment = "Absolutely no wind the last 18 hours.<BR>Solarcharger went into FLOAT, because the battery was full.";
> <?php
> $date = "2017-07-24";
> $time = "23:59";
> $wh_solar = "1125";
> $wh_wind = "2";
> $comment = "Only very little wind.";
>
> what I need is, to split the file from <?php to the line before the next
> one and save it with the date as e.g. 2017-07-23.data
>
> How can I do this mos easyly?
>
> Thanks in avance
> Michelle
>
well, a bash script solution might be fancy here. It is slow but rather
easy to configure:
#!/bin/bash
while read -r LINE;
do
CONTENT="$CONTENT$LINE
";
if [[ "${LINE:0:8}" == '$comment' ]]; then
echo "$CONTENT" > $date.data
CONTENT=""
else
eval $(sed 's|^\$||;s|\s*||g' <<< "$LINE" ) # instantiates the variables for further use
fi
done < yourfile
the variables in the file are actually instantiated so you can use them
within the script (as in $date.data).
------------------------------------
------------------------------------
--
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/sed-users/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/