[Swift-user] Read file and write to files

Michael Wilde wilde at mcs.anl.gov
Thu Jan 28 05:35:47 CST 2010


Jamal,

You can use an approach like this:

Use readData() to read list.txt into an array.

Use foreach to iterate over the array.

Use the index of the array to form the new file names,
and a single_file_mapper to map a variable inside the
foreach to these files.

Use an app() like echo() to write the text to the files.

- Mike



----- Original Message ----- 
From: "J A" <jamalphd at gmail.com> 
To: swift-user at ci.uchicago.edu 
Sent: Tuesday, January 26, 2010 10:58:17 PM GMT -06:00 US/Canada Central 
Subject: [Swift-user] Read file and write to files 


Hi All: 

I am still learning the swift script. 

I have a text file (list.txt) contains the following: 


3 
String1 
String2 
String3 


Where the first line contains the number of sentence with text. 

I would like to read the file list.txt and output the strings into separate files where file1.txt contains "String1", file2.txt contains "String2", and so on. 

Any suggestions on what to use or a sample code will be appreciated. 

Thanks, 
Jamal 


_______________________________________________ Swift-user mailing list Swift-user at ci.uchicago.edu http://mail.ci.uchicago.edu/mailman/listinfo/swift-user 



More information about the Swift-user mailing list