Fastest way to remove the first x characters from a very long string

Denis McMahon denismfmcmahon at gmail.com
Sat May 16 19:24:04 EDT 2015


On Sat, 16 May 2015 06:28:19 -0700, bruceg113355 wrote:

> I have a string that contains 10 million characters.
> 
> The string is formatted as:
> 
> "0000001 : some hexadecimal text ... \n 0000002 : some hexadecimal text
> ... \n 0000003 : some hexadecimal text ... \n ...
> 0100000 : some hexadecimal text ... \n 0100001 : some hexadecimal text
> ... \n"
> 
> and I need the string to look like:
> 
> "some hexadecimal text ... \n some hexadecimal text ... \n some
> hexadecimal text ... \n ...
> some hexadecimal text ... \n some hexadecimal text ... \n"

Looks to me as if you have a 10 Mbyte encoded file with line numbers as 
ascii text and you're trying to strip the line numbers before decoding 
the file.

Are you looking for a one-off solution, or do you have a lot of these 
files?

If you have a lot of files to process, you could try using something like 
sed.

sed -i.old 's/^\d+ : //' *.ext

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list