3

I would like to be able to generate a large number of digits (for example, the first one million decimal digits of the Napier constant) and then save the number in a text file without any line breaks.

I cannot seem to be able to do this in either GEdit or LibreOffice Writer though. I use Maxima on Terminal to generate the numbers, but they are outputted with line breaks.

I either need to find a way to generate the numbers without line breaks, or find a text editor that can handle removing the line breaks from large numbers containing millions of digits (I can remove the line breaks from numbers containing thousands of digits without any problems).

I use the Terminal syntax below to generate the first one million decimal digits of the Napier constant, and then copy and paste the digits into a text editor (removing \\ and \n).

sudo apt-get install wxmaxima

maxima

bfloat(%e),fpprec:1000000;

What happens when I attempt to copy and paste into GEdit and then remove the line breaks, is I can get the digits all on one line, but the digits will not display. Since GEdit can successfully remove the line breaks from and display 1000 digits but not one million digits, I am wondering if it might be a memory issue. However, when I attempt to save the file as TXT and then open it in LibreOffice instead, it still contains line breaks. LibreOffice cannot seem to remove the line breaks at all, even when I copy and paste directly from Terminal.

I should add maybe that I am not on Canonical Ubuntu, but the fork known as Mint :-/ .

muru
  • 207,228

2 Answers2

5

IMHO the right way to do this is to avoid copy-pasting the text altogether, by writing the maxima output directly to file:

x:bfloat(%e),fpprec:1000000$
stringout("my_big_number.txt",x);

$ in place of ; in the first expression just suppresses the - rather large - console output.

You can confirm there are no additional newlines in the output file using wc:

$ wc my_big_number.txt
      2       1 1000006 my_big_number.txt

(in fact, there's one additional newline, since stringout appears to insert a single blank line before the output; however there are none within the numerical output itself).

You can then convert the text file to whatever other format you wish - since you have LibreOffice installed, using its standalone conversion filters:

$ libreoffice --convert-to pdf my_big_number.txt
$ xdg-open my_big_number.pdf 

Alternatively you could use LO's unoconv command-line utility:

$ unoconv -f pdf my_big_number.txt 

See for example How to convert TXT to PDF?

steeldriver
  • 142,475
4

GEdit (and Libreoffice) aren't the right tools for this.

If I understand you right, then you want to convert

123456\n

into

123456

Use Perl, for instance:

perl -pe 'chomp' your_input_file.txt > without_newlines.txt

Update The input file turned out to have not only linebreaks, but also a line continuation character \ at the end, i.e.:

2.7182818284590452353602874713526624977572470936999595749669676277240766\
303535475945713821785251664274274663919320030599218174135966290435729003342952\
605956307381323286279434907632338298807531952510190115738341879307021540891499\
348841675092447614606680822648001684774118537423454424371075390777449920695517\
...

To remove them (as well as the linebreaks) the following command will do:

perl -pe 'chomp; s/\\//;' your_input_file.txt > without_newlines.txt
PerlDuck
  • 13,885