Re: Spliting file and save it with date...

"[email protected] [sed-users]" <[email protected]> 18 Sep 2017 16:09:05 +0000
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
"well, a bash script solution might be fancy here. It is slow but rather
 easy to configure:"
 

 I agree with the basic idea. Parsing the data with a bash script is a reasonable solution, and not that difficult. However, when I run the script, I get an error.
 

 $ cat script.sh
#!/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" )
fi
done < thephpfile

 

 $ cat thephpfile
<?php
$date     = "2017-07-23";
$time     = "23:59";
$dummy    = "EOD";
<?php
$date     = "2017-07-24";
$time     = "23:59";
$dummy    = "1125";

 

 $ ./script.sh
./script.sh: line 11: ?php: No such file or directory
./script.sh: line 11: ?php: No such file or directory

 

 On the face of it, seems the bash script ends up interpreting "<?php" as trying to read input from "?php" file... One simple solution would be to just get rid of those lines before processing the file, and key on the $date lines as the start of each record.
 

 Daniel
 



[Non-text portions of this message have been removed]