Solved

mangling a text file

Posted on 2014-09-23
4
300 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 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

832 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