Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mangling a text file

Posted on 2014-09-23
4
Medium Priority
?
343 Views
Last Modified: 2014-09-30
Ok so I have a flat comma file that has 20k lines that I need to manipulate.  Each line should represent a unique path to a unique filename comma separated.  It is not possible to re-generate or re-export the data so this is my only option that I have to work with.  Example it should look like this:

user1@foo.org\1234.dat
user1@foo.org\1879.dat
user1@foo.org\28743.dat
user2@foo.org\123.dat
user2@foo.org\123425.dat
user3@foo.org\9090.dat
user4@foo.org\90786.dat
...

what the file looks like is

user1@foo.org,
1234.dat,
1879.dat,
28743.dat,
user2@foo.org,
123.dat,
123425.dat,
user3@foo.org,
9090.dat,
user4@foo.org,
90786.dat
...

The number of files per user varies from 1 to 50 or more but is never zero.  I need someway to parse the file and rewrite it in the "what it should look like" format.
0
Comment
Question by:avatech
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 40340037
pseudo code:

string user;
string line;

StreamReader sr = readFromFile();

while (line = sr.ReadLine())
{
   if (line.Contains("@") )
   {
     user = line.Trim(',');
     continue;
   }
    File.WriteLine (user + "\\" + line.Trim(",");
}
0
 
LVL 4

Author Comment

by:avatech
ID: 40345901
I'll give that a shot and see where that leads.  Thanks
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 40346178
let me know if you need more help . . . post the code if it'll help.
0
 
LVL 4

Author Closing Comment

by:avatech
ID: 40352547
That worked perfectly - thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Starting up a Project
Screencast - Getting to Know the Pipeline

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question