Solved

mangling a text file

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

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 39

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now