Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.