# Output Export in Mathematica

I have a command line that generates lists as output and is running in a loop, so generates, multiple long lists. Each list is to be exported as a .txt file. How can I automate the name generation of the output files. I intend to use the same name as the input file but with the .txt extension in output of course.

For[
i = 1,i < 3,i++,
outdata = ReadList[ test[[i]], Record, RecordSeparators -> {{">"},{" "}} ];
Print[outdata]
]


How can I automate the export?

-

Something like the following should do:

For[i = 1, i < 3, i++,
outdata = ReadList[test[[i]], Record, RecordSeparators -> {{">"}, {" "}}];
Export[FileBaseName[test[[i]]] <> IntegerString[3, 10, i] <> ".txt", outdata,"List"]
];


FileBaseName strips the file name in test[[i]] from its extension (if it has any). IntegerString[3, 10, i] generates strings of the form "001", "002", "003" etc. and <> (StringJoin) glues the substrings together.

There is a number of output formats you could use in Export. I chose "List" but you may want to examine the BasicFormats guide page for more.

-
Thank you, but i actually figured out another way! –  Aparajita Lahree Mar 12 '13 at 12:45
For[i = 10, i < 20, i++,outdata =ReadList[test[[i]], Record, RecordSeparators -> {{">"}, {" "}}]; prin = "n" <> Riffle /@ (ToString /@ #) & /@ worklist[[i]] <> ".txt"; Export[prin, outdata]] –  Aparajita Lahree Mar 12 '13 at 12:46