LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-04-2013, 01:03 PM   #1
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Rep: Reputation: 24
show/edit txt file metadata


How can I show and edit the metadata of txt format ebooks in linux? I can do what I need with calibre, but I want to automate the process with command line utilities instead
 
Old 04-05-2013, 11:48 PM   #2
gangadhar402
Member
 
Registered: Mar 2013
Location: the India
Distribution: Ubuntu,Debian and CentOS
Posts: 35

Rep: Reputation: 2
Hi,

write a simple script with following
wget - to down load the html of url

strstr()-search a string (metadada) in that file

you will also try with curl

will help you
 
1 members found this post helpful.
Old 04-06-2013, 12:41 PM   #3
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by gangadhar402 View Post
Hi,

write a simple script with following
wget - to down load the html of url

strstr()-search a string (metadada) in that file

you will also try with curl

will help you
You lost me at wget, for many of these files there is no url to download that I'm aware of.

Calibre will create the minimum necessary metadata for them (all I actually have to do is supply calibre with the author name), without any connection to the net.

I believe this added metadata is inserted in the txt files headers by calibre, because:
if I pass the unmodified txt files to my ereader, it organizes them in its database by filename and modification date, which is not very useful for me;
but if I add the author name to these txt files using calibre's Metadata Edit process and then pass just the modified txt files to my ereader, its database now makes files available by filename, author or modification date.

This information is not contained in the body of the txt file concerned. The only place it can be is in the file header, so all I'm actually seeking is a command line tool that will show and edit the content of file headers.
 
Old 04-08-2013, 07:02 AM   #4
gangadhar402
Member
 
Registered: Mar 2013
Location: the India
Distribution: Ubuntu,Debian and CentOS
Posts: 35

Rep: Reputation: 2
hi,

from the command line I did not tried this one ...
but it's quit easy with simple code, it's easy to extract any thing from files.........

do you have links for that files,then I can see those files.In past,I had some experience with these metatags.that time I was written code based on wget and some string functions .....

we can extract any thing from that file by using simple scripts ....
you need not require wget here...
because you already have those files with you ...

inside of the code
use fopen() /open()
read the file by character by character..
search for what ever you want ...

like
author name,
last revised,
and what ever you want ..

so that you can able to show them and also you can able to edit

Last edited by gangadhar402; 04-08-2013 at 07:06 AM.
 
Old 04-08-2013, 12:50 PM   #5
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by gangadhar402 View Post
hi,

from the command line I did not tried this one ...
but it's quit easy with simple code, it's easy to extract any thing from files.........

do you have links for that files,then I can see those files.In past,I had some experience with these metatags.that time I was written code based on wget and some string functions .....

we can extract any thing from that file by using simple scripts ....
you need not require wget here...
because you already have those files with you ...

inside of the code
use fopen() /open()
read the file by character by character..
search for what ever you want ...

like
author name,
last revised,
and what ever you want ..

so that you can able to show them and also you can able to edit
We seem to be talking at cross purposes. What scripting language are you referring to? Neither open nor fopen exist in bash, the only scripting language I am familiar with. Nothing I know of, not even hex editors like bpe, actually show the file header. touch can modify certain content in the header but does not show its layout.
 
Old 04-09-2013, 12:45 PM   #6
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 515

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by porphyry5 View Post
I believe this added metadata is inserted in the txt files headers by calibre, because:
if I pass the unmodified txt files to my ereader, it organizes them in its database by filename and modification date, which is not very useful for me;
but if I add the author name to these txt files using calibre's Metadata Edit process and then pass just the modified txt files to my ereader, its database now makes files available by filename, author or modification date.
I'm under the impression that your ereader is using the filename of the text files to do the sorting, since Calibre will rename any file you add to its database based on the author and title provided.

Quote:
Originally Posted by porphyry5 View Post
This information is not contained in the body of the txt file concerned. The only place it can be is in the file header, so all I'm actually seeking is a command line tool that will show and edit the content of file headers.
AFAIK, text files do not have any metadata nor header, they're just plain text.
 
Old 04-09-2013, 01:41 PM   #7
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by Diantre View Post
I'm under the impression that your ereader is using the filename of the text files to do the sorting, since Calibre will rename any file you add to its database based on the author and title provided.
Correct, but some text files that I obtained from Project Gutenberg are not accepted by Calibre at all, it will not add them to its library, giving the error message "Failed to read metadata from the following ..." Other text files it makes no objection to.

Quote:
Originally Posted by Diantre View Post
AFAIK, text files do not have any metadata nor header, they're just plain text.
Every file has a header of some sort, with at least access, modification and creation dates, size data etc. But I think you are correct about text files having no metadata. Examining what is actually on my ereader with ls, rather than what the ereader claims is there, reveals the presence of 2 files, metadata.calibre and driveinfo.calibre. If I remove them, the reader reverts to file name only organization of its data base.

But as it turns out, as all I wanted was to have the files organized by file name within author, the simplest way of achieving that effect was to rename the files, making the author name the first part of every file name. That way I get the desired effect with just the data base organized by file name. So I'm marking this thread as solved even though Ive not got the original question answered. I thank you all for your help.
 
Old 12-07-2018, 05:36 PM   #8
miriam-e
LQ Newbie
 
Registered: Nov 2011
Location: QLD, Australia
Distribution: Puppy Linux
Posts: 29

Rep: Reputation: Disabled
I know this thread is kinda old, but I just spent a while trying to solve the same problem, for a slightly different reason.

I found, as porphyry5 did, that Calibre doesn't store the metadata in the text file itself. The only thing that Calibre reads from the text file is the filename, but if you have a second file in the same directory with the same basename, but with extension "opf" then it will read all the metadata from it. That is, if your text file is "test.txt" and a file named "test.opf" is in the same directory, then when Calibre reads the text file (for example if you grab it with your mouse and drop it onto Calibre's window) then Calibre will get the metadata from the opf file.

The opf file is a standard (rather cumbersome) XML ebook metadata file. You can examine one by clicking on the text "Click to open" next to the label "Path:" in the right-hand column (panel?) when a file selected in Calibre's file list. When you add a text file it will automatically generate an opf file. If the ebook added is an epub file then it will copy the opf file from the one inside the epub ebook (which is really just a zip file containing html+images+metadata files).

As an aside, I'll explain why I wanted to store metadata for a text file:
Having suffered, over the years, some computer crashes that have trashed disks and having helped other people who've had their disks trashed, I've become very interested in recovering files from broken filing systems. One of the biggest problems is that much important data (filename, date, owner, etc) are held in the directory pointers, and often not in the files themselves. So I've begun a system of saving as much metadata in the actual files as possible to aid in recovery if ever needed.

With some files that's easy. Most picture formats let you store metadata inside them, for example jpeg EXIF data. Some sound file formats let you store metadata -- notably mp3 lets you store tremendous amounts of metadata in their ID3v2 tags, even pictures! Well, I'm a writer and wanted to store useful metadata in my text files. I'd begun storing the filename in the first line, the full directory path on the second line, and the date and time the file was created on the third line.

This morning I was writing a quick bash script to fix the author and title metadata in some epub ebooks, so I don't have to open them each time in Calibre to time-consumingly do it by hand (it's very easy to script things for Calibre using its "ebook-meta" command), and suddenly it occurred to me that Calibre might have a standard way to store metadata in text files. Sadly, it doesn't. As I mentioned above, it stores the data in a separate opf file, which is fine if your directory structure is intact, but if you're recovering a filing system after a bad crash then it is totally useless. [sigh]

Last edited by miriam-e; 12-07-2018 at 05:41 PM.
 
Old 12-07-2018, 10:52 PM   #9
Cindywendt
LQ Newbie
 
Registered: Dec 2018
Posts: 1

Rep: Reputation: Disabled
Awesome and wonderfull
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I use Shell script to edit a data at a particular location in a txt file? leena_d Programming 30 02-08-2010 12:43 AM
How can I use Shell script to edit row 23 column 5-8 in a txt file? leena_d Linux - Newbie 4 12-14-2009 03:43 AM
LXer: vimdiff - Edit two or Three versions of a file with Vim and show differences LXer Syndicated Linux News 0 04-09-2009 12:21 AM
Edit txt file imkornhulio Programming 6 01-22-2009 05:36 PM
how to edit a txt file through console safrout Linux - Newbie 5 01-31-2003 07:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration