Click to See Complete Forum and Search --> : editing files


zmerlinz
04-29-2003, 10:35 AM
i have a file that has 100,000 lines in it, and what i need to do is remove the first column of text and just leave the numbers

i wondered if i could use the more command and grep and then put the output to a new file

so basically all i want left is just the numbers in one long line

i would normally use a text editor or something like that, but most of them don't like this file

and doing it manually is just mad

anyone got any ideas how i could do this

here is an example file that i will be using, this one only has two lines (the one with 100,000 lines is a few megs :P )

cheers

evac-q8r
04-29-2003, 10:49 AM
Use the cut command. Refer to the man pages for additional info. You can select out exactly which colmun bytes you want to discard.

EVAC

zmerlinz
04-29-2003, 10:53 AM
i'm not sure how the cut command would work with this file as some of the characters in first column also contain *'s ??

evac-q8r
04-29-2003, 10:58 AM
I'm not sure if you're familiar with the editor nedit. If you have this one installed you can also delete out columns of information. Normally when you select text it will select all the way to the end of the line which is obviously what you don't want, that is, with a mouse click (left) and hold. However, in this editor if you wanted to select text that doesn't go all the way to the end of line, i.e. a column of N bytes, you can hold the CTRL key along with the moust left click CTRL-LMOUSE and you will be able to that as well. This files has many lines in it though and it may not be all that efficient, but it sure as heck beats trying to delete each line. That's impossible.

EVAC

evac-q8r
04-29-2003, 11:06 AM
cut -c14-29 data2.txt > newfile.txt

The 29 is based off of the assumption that the number in the file you gave me is the absolute longest one. If it isn't and you want to keep the precision of your numbers you may need to change 29 to something a little larger. The command just selects out the 14th byte to the 29 byte and discards the rest. You should have success with this.

EVAC

zmerlinz
04-29-2003, 11:08 AM
Originally posted by evac-q8r
cut -c14-29 data2.txt > newfile.txt

The 29 is based off of the assumption that the number in the file you gave me is the absolute longest one. If it isn't and you want to keep the precision of your numbers you may need to change 29 to something a little larger. The command just selects out the 14th byte to the 29 byte and discards the rest. You should have success with this.

EVAC

unfourtunatly the numbers have different amounts of decimal places, but i will look at the txt editor though :D

evac-q8r
04-29-2003, 11:13 AM
Well the command I suggested you use works because I just tested it. Does it not work for you. You shouldn't need to use the text editor because that is going to involve a little more patience to highlight 100,000 lines of text and it just may not be able to highlight that much.

EVAC

zmerlinz
04-29-2003, 11:38 AM
i will give the command a go, but what happens if the number that i specify exeeds the length of the longest one ?

zmerlinz
04-29-2003, 11:45 AM
i used the command in the end and it worked :D

cheers :d

evac-q8r
04-29-2003, 11:46 AM
Then it just exceeds the length of the longest one and you'll be left with some spaces at the end. If your worried about corrupting the original file, that is what the > is for. It redirects the output to the newfile.txt. Even if you don't include "> filename.txt" it will just direct the output to the screen.

EVAC

zmerlinz
04-29-2003, 11:48 AM
ok didn't quite work there is ^M at the end of all the lines

evac-q8r
04-29-2003, 11:53 AM
I think you have the hang of it now :cool:

EVAC

zmerlinz
04-29-2003, 12:08 PM
yup

cheers and thanks for your help

:cool:

bwkaz
04-29-2003, 02:45 PM
Originally posted by zmerlinz
ok didn't quite work there is ^M at the end of all the lines Run dos2unix on them. ;)

If you need source for it, I've got it laying around here somewhere.