Batch file to create many files with special characters

Posted by MollyO on Super User See other posts from Super User or by MollyO
Published on 2013-11-05T21:42:39Z Indexed on 2013/11/05 21:57 UTC
Read the original article Hit count: 276

Filed under:
|
|
|
|

Essential info: I have a file "DB_OUTPUT.TXT" with 304 lines that I need to turn into 304 files (one per line). Each line contains many special characters and may be up to tens of thousands of characters long. For these reasons, I'm having difficulty using a cmd.exe batch file (which limits the amount of input) and the echo command (which would try to execute each special character, short of me having to escape them all).

I also have a file "DB_OUTPUT_FILENAMES.TXT" containing a distinct filename for each line-soon-to-be-file from "db_output.txt". So line 1 of DB_OUTPUT.TXT needs to be the body of a new file with a name equal to line 1 of DB_OUTPUT_FILENAMES.TXT.

Extra info: As you may have guessed, DB_OUTPUT.TXT is output from a database; it contains 304 records with 6 or 7 columns at a fixed width with the last column being a SQL query. Each of these lines (db records) will be used as a script to create new database objects, which is why the special characters need to be preserved.

Question: Is there a way to do this in a batch-like fashion? I'd be happy with either a Windows solution or a Linux one.

© Super User or respective owner

Related posts about linux

Related posts about Windows