PDA

View Full Version : How do I parse a text file in DOS?



jasong
07-30-2006, 07:36 PM
Sorry if this is mildly off-topic, but my search was getting frustrating.

I have a text file with well-defined columns that I want to use to make a new file with one column on the left side. Basically, I need to be able to take the first number in the first(leftmost) column, print it to the top line of a new file, go to the top of the next column and this that number in the new file on the second line, etc. When it gets to the end of the line, it would go on to the next line.

Basically, it would read like an English speaking person, but in the new file each number would have it's own line.

Btw, the file is a list of the first million prime numbers. I'm trying to find factorial primes(a factorial number is a# where all numbers from 2 to that number that are prime are multiplied together. The full formula I'm using is a#+/-1)

IronBits
07-30-2006, 08:30 PM
Show an example.

jasong
07-31-2006, 05:43 PM
Show an example.
The beginning of the file:

The First 1,000,000 Primes (from primes.utm.edu)

2 3 5 7 11 13 17 19
23 29 31 37 41 43 47 53
59 61 67 71 73 79 83 89
97 101 103 107 109 113 127 131
137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223
227 229 233 239 241 251 257 263

What I want:

2
3
5
7
11
13
17
19
etc.

Btw, the spaces between numbers are actually bigger in the original document(Maybe hitting reply and looking at the resultant quote will get you the actual spacing).

Btw#2 Dell has a crappy reinstall method which has never worked for me, so my XP installation doesn't have a Paint program for me to copy my desktop to. Sorry.:cry:

Bok
07-31-2006, 06:00 PM
Send the file to me or tell me where it is and I'll do it on linux..

It just needs a simple replace of each space with a carriage return..

in linux within vi this is :1,$s/ /^M/g

I'm sure you could somehow do a similar replace command with an advanced editor perhaps like Crimson Editor (http://www.crimsoneditor.com)

Bok

alpha
07-31-2006, 06:04 PM
Or you could just use the Windows version of Vim (ftp://ftp.vim.org/pub/vim/pc/gvim70.exe).

Bok
07-31-2006, 06:14 PM
True,

I never think of windows running vi, but I did once try it many years ago...

Bok :thumbs:

jasong
08-01-2006, 03:53 PM
I'll do a websearch on Vim. thanks guys.

edit:
MAIN AUTHOR

Send any other comments, patches, pizza and suggestions to:

Bram Moolenaar E-mail: Bram@vim.org
Molenstraat 2
2161 HP Lisse
The Netherlands

This is the address of my parents, they will forward mail and eat the pizza.
My actual address will change a couple of times in 2006.
I'm just crazy enough to maybe send that pizza. Are there any pizza joints in the Netherlands that accept American debit cards?(and email?)

jasong
08-01-2006, 05:34 PM
There is a lot of stuff in Vi, but I can't seem to figure out what I should do in my particular case.

Maybe somebody out there with some programming skills can write a program that takes every string with a space before it and puts everything in columns?

Bok
08-01-2006, 06:15 PM
Load it in vim, then type

:1,$s/ /[CTRL-V][CTRL-M]/g

which means got from line 1, to end of file ($) and do a change (s) of all spaces to EOF's globally (g)

then :wq! to save it

and by [CTRL-V][CTRL-M] I mean it as control characters not literally type what I've put in...

Or tell me where the file is and I'll do it for you.

Bok

jasong
08-01-2006, 08:35 PM
Load it in vim, then type

:1,$s/ /[CTRL-V][CTRL-M]/g

which means got from line 1, to end of file ($) and do a change (s) of all spaces to EOF's globally (g)

then :wq! to save it

and by [CTRL-V][CTRL-M] I mean it as control characters not literally type what I've put in...

Or tell me where the file is and I'll do it for you.

Bok
When I pressed Ctrl-M it said pattern not found.

I'll tell you what Bok, give me a place to upload the file. If you figure out how to do it in Vim please send me the instructions and the new file. I will then very happily put my one dual-core computer on whatever project you want and use whatever name on it you want for a week.

Edit: Never mind about the upload, the file is at prime pages. A Google search should find it for you.

Bok
08-01-2006, 10:23 PM
Here you go

primes (http://stats.free-dc.org/primes1.zip)

Bok

jasong
08-02-2006, 12:00 AM
Here you go

primes (http://stats.free-dc.org/primes1.zip)

Bok
thanks, Bok, that works great.

Darkness Productions
08-04-2006, 10:51 AM
Bok -

Just as a random note, instead of doing :1,$s, you can just do :%s. Just a little tidbit ;)

Bok
08-04-2006, 05:27 PM
old habits die hard :)