The requirement is several hundred files. Naming rules are similar to the following file name:
dailydata_20140320.txt
When combined through newlisp, these file names are automatically generated, read the content using read-file, and write the content to a file using append-file.
Note that the result of the previous operation should be deleted, and the error. log should be generated if the file does not exist.
The Code is as follows:
#!/usr/bin/newlisp(set ‘start-date "20140101 00:00")(set ‘start-seconds (date-parse start-date "%Y%m%d %H:%M"))(set ‘day-seconds (* 3600 24))(if (file? "20140101_20140828.txt") (delete-file "20140101_20140828.txt"))(if (file? "error.log") (delete-file "error.log"))(set ‘x 0)(while (< x 240) (begin (set‘ compute-date (date (+ (* day-seconds x) start-seconds) 0 "%Y%m%d")) (set ‘file-name (string "dailydata_" compute-date ".txt")) (if (file? file-name) (begin (set ‘file-content (read-file file-name)) (print file-content) (append-file "20140101_20140828.txt" file-content) ) (append-file "error.log" (string file-name " does not exist"))) (inc x) ))(exit)
Merge newlisp files