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

"[email protected] [sed-users]" <[email protected]> 19 Sep 2017 05:24:28 +0000
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>

 We need to follow the KISS methodology here:
 

 #!/bin/bash
 set --;
 fname=;
 while IFS= read -r L; do
    case $L in
       '<?php' )
          [ "X$fname" = 'X' ] || printf '%s\n' ${1+"$@"} > "$fname.data"
          set -- "$L"
          fname=
          continue ;;
 

       '$date '*=* ) fname=${L#*\"} fname=${fname%\"*} ;;
    esac
    set -- ${1+"$@"} "$L"
 done < input.file
 printf '%s\n' ${1+"$@"} > "$fname.data"
 

 ##########################################
 

 Or, with Perl:
 

 perl   -Mautodie=open  -aF'/(?=<\?php$)/m'   -0777ne '
    for ( @F ) {
       open my $fh, ">", (/^\$date\h*=\h*"(.*?)";$/m)[0] . ".data";
       print $fh $_;
    }
 ' input.file

 


 



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