I'm exporting MS Word content to plain text for use with text&file utilities. I have a constraint where the line numbering feature has been enabled in the MS software, and any reference to line numbers in the final output must match that numbering. So enter "numbering lines":
Obviously for Word, that sort of numbering doesn't break lines at newline, it breaks "lines" after the right margin (or something). A script like
docx2txt, doesn't account for this by default it seems and breaks lines at newline. So if I use
grep -n with numbering, the lines won't match the source line numbers feature, as illustrated above. It's not exactly clear from the documentation how I would need to edit the Perl script to convert the files the way I need to in this case:
our $config_newLine = "\n"; # Alternative is "\r\n". our $config_lineWidth = 80; # Line width, used for short line justification.
I tried substituting
\r\n but that doesn't seem to work for me. So I resorted to exporting the documents directly from Word with the following settings(save as plain text, on v.2013,64pc):
- Insert line breaks + end lines with (CR/LF)
- Allow character substitution
And now indeed when I use the
.txt files there is a perfect match between line numbers in the source numbering feature and the
grep -n output.
- Is there any specific configuration/process I should know about
docx2txtor a similar command line utility which would have allowed me to convert my .docx files to plain text while preserving line breaks, without resorting to Word like I did?
- What are the best practices, if any, for exporting MS Word documents (which may contain accented characters) to plain text for use with file/text utilities, with respect to line breaks and formatting; and are there any negative implications with the settings I chose for exporting i.e. inserting CR/LF?
As suggested I provide a sample. In this rar archive, I bundled a .docx file with simple paragraphs, and its exported .txt file using Word with the aforementioned options. The latter can be compared with a default run of
docx2txt on the source file.