Solved

mangling a text file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
word0 challenge 3 78
groovy example issue 10 90
index Out OF Range Exception error 4 54
C# application error "Parameter Is Not Valid". 3 79
A short article about a problem I had getting the GPS LocationListener working.
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.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now