Solved

mangling a text file

Posted on 2014-09-23
4
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 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 40

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

Industry Leaders: 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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.

710 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