comma delimited file
I have a comma delimited file that I want to get into a database. The file contains three lines of data for each record. The database program I'm using reads each line as a separate record, so I can't get the DB program to read the file properly.
I need a way to get the three lines onto one line so the DB program can read it. There are far too many records to do this by hand. From looking at some things, I would think there must be an easy way to do this with something like perl. Any suggestions?
I have little experience with perl but I am learning, and I am willing to learn something else if perl isn't the right way to go. I know some people post on here hoping someone will just give them the solution. If someone wants to do that, that's fine with me (it would certainly simplify things for me). But I hope to at least get a direction to go in on this issue. Thanks in advance.
Try posting a 4-5 line example of what the file looks like now and what you need it to look like.
It looks like this:
1, a, b, c
1, d, e, f, g
1, h, i, j, k
1, l, m, n, o
2, a, b, c
I need it to look like this:
1, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o
2, a, b, c, etc.
It would be okay if the "1"s were in there as well.
I'm not sure from your example which way you wanted it. Your first post stated every three lines. Your example showed that the lines were indexed by a number and you should join all the numbers. So I tried it both ways. The first example will split by indexed lines, the second will join every three lines.
Let me know if this works for you.
Change the 'datafile' to be whatever the name is of your datafile.
Okay, the second one is doing the job nicely. Thank you very much.
One last thing, and I feel like I'm missing something simple here, how do I get the output into a new file? It seems to just be showing it to me and not altering the file or creating a new one.
I need a good shake to get the neurons working . . .
Okay, neurons working now. Output going into file. Thanks again.
|All times are GMT -5. The time now is 04:59 PM.|