Register
It is currently Tue Jul 22, 2014 1:20 am

Rename files with first line


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed May 12, 2010 1:41 am   

Joined: Wed May 12, 2010 1:24 am
Posts: 2
Hi everyone

I don't have any real experience in bash scripting.. Las week I accidentally erased the wrong partition an got all my mothers files lost, I recover them with foremost but now I have 800 *doc files with numbers instead of names. Is there any way of making a script that reads the first line in a *doc file and rename it with it?

Please help, I relay need this


Top
 Profile  
 PostPosted: Wed May 12, 2010 2:09 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
Hi,

something like this (I didn't test)
if all files are in the same directory:
Code:
for i in *.doc; do mv $1 $(sed -n '1s/[[:punct:]]\| /_/gp' $1).doc; done


otherwise:
Code:
find ~ -type f -iname "[0-9]*.doc" -exec bash -c 'mv $1 $(sed -n '1s/[[:punct:]]\| /_/gp' $1).doc' _ {} \;
all on one line.
where ~ is your own /home/bnalohim directory (just change ~ to where you want to start changes to be made).


Last edited by Watael on Wed May 12, 2010 2:29 pm, edited 2 times in total.

Top
 Profile  
 PostPosted: Wed May 12, 2010 10:22 am   

Joined: Wed May 12, 2010 1:24 am
Posts: 2
Thank you, but It didnt worked, it just made the files unreadable...

Ill explain with more details, I have 781 microsoft word .doc files in the directory /home/sva/output/doc.. all of them have names like "191195052.doc"... inside the document the first line is the title, ex. "EVALUACIÓN DE CIENCIAS SOCIALES " (my mother is a teacher)... what I need is to rename the doc file with the first line inside of it...

thank you, any idea will be great


Top
 Profile  
 PostPosted: Fri May 14, 2010 8:49 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
You probably need to get the text out of the doc files. A program like wvText (from http://wvware.sourceforge.net) might be useful for that.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP