i am trying to read an odt file from terminal. When i type cat myfile.odt it shows me an image like this
3 Answers
Libreoffice format has the text within a compressed section of a binary file, so cat
doesn't work. There is an option: lowriter --convert-to example.txt
which will repackage it, & there is a --print option if that's what you wanted. man lowriter
is informative.

- 2,580
-
this answer should be on top : it doesn't try to fix the method the OP tried, but to fix the problem the OP had (ie : displaying a .odf content from the terminal). +1 (see: http://meta.stackexchange.com/a/66378/235138) – Olivier Dulac Sep 23 '16 at 11:06
-
oops, I should have given the link to the 2nd (and best) answer (explaining better the concept of XYProblem) : http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/233676#233676 . But I'm glad that your answer is now the top answer! – Olivier Dulac Sep 23 '16 at 14:10
-
3
-
cat
works in the sense that it functions correctly. It doesn't work in this context, ie doing what the OP intended the outcome to be. It is to be hoped that we can avoid superfluous pedantry when the context is clear, because I fear that merely muddies the waters of usefulness :)cat
is of course an immensely useful tool - in the correct context. This is an important point - it isn't a tool requiring complex options, and doesn't attempt to please everyone - the route to bloatware! – Mark Williams Sep 24 '16 at 09:14
Why it does not work as you expected
cat
works on text files. An odt file is technically (and very simplified) a ziped folder containing some xml files.
As such 'cat' can not be used for this purpose. It works only on plain text.
What you can do instead
You could of course extract it and parse the respective xml files, but I guess this is overkill for your purposes.
An alternative for what you are trying is:
odt2txt --stdout file.odt
this will provide the same as cat on a txt file, but will take more time depending on the size of the file. you will need to have unoconv installed
sudo apt install unoconv

- 10,542
The odt file is a zip package that include formatting and other features for the document.
I you want to see the content of an odt file you would have to unzip. The actual words contained in the document is in the content.xml
file.
Micosoft word documents (*.docx) is the same type of package. The text of a word documents is in a file of a zipped sudirectory named document.xml
.
I wrote a script to perform text search on my documents. The script would take two argument for the file (filename and text to find), extract the file to a temp folder, grep the contents of the xml file then display the filename that matches the text searched.
Sample Script to search all odt files in a directory and it's subdirectories:
#!/bin/bash
directory="$1"
string="$2"
tempdir="/tmp/searchdir"
echo "Searching directory [$directory] for [$string]"
echo "---------------------------------------------"
if [ $# -ne 2 ]; then
echo "Parameter error... Usage: [Directory to Search] [String to search]"
echo "Note: Use quotes if spaces are included in directory or search string."
echo "Exiting..."
exit 1
fi
mkdir $tempdir
while IFS= read -r -d '' i;
do
# echo Processing: $i
unzip -o "$i" -d $tempdir content.xml > /dev/null 2>&1
found=$(egrep -i "$string" $tempdir/content.xml)
if [[ "$found" ]]; then
echo "Found in [$i]"
fi
[[ -f /tmp/content.xml ]] && rm /tmp/content.xml # remove the temporary file if exist
done < <(find $directory -name \*odt -print0)
rm -r $tempdir

- 25,036
-
1Nice that you wrote a script, but without including it into your answer or providing a link, it is not very useful... – Byte Commander Sep 23 '16 at 18:31
-
.odt
file is a binary, so when youcat
it, you shouldn't expect you can understand the output. :) – edwinksl Sep 23 '16 at 08:36