Merge newlisp files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.