LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2009, 03:47 AM   #1
nandelbosc
LQ Newbie
 
Registered: Nov 2009
Location: Olot, Catalunya
Distribution: Ubuntu, Gentoo
Posts: 9

Rep: Reputation: 0
Help renaming files


Hi gurus!

I have this script...

Code:
#!/bin/bash

LIST='ls *.pdf'
for i in $LIST ;
#for file in originals/*.pdf
do
	gs -r300x300 -sDEVICE=tiffgray -sOutputFile=albara.tif -dBATCH -dNOPAUSE $i
	tesseract albara.tif albara -l spa
	cat albara.txt | grep -A 1 Data | tail -1 | cut -c 1-10 | sed -e "s/.*/mv $i mod\/&.pdf/" > execute; sh execute && rm -f execute
	rm albara.txt
	rm albara.tif
done
1. the script list all PDF files in a directory
2. transform it to TIFF
3. recognizes all the text with tesseract
4. changes the original name with the first 10 characters
5. finally deletes the temp files

The problem is in the step number 4 and the 10 characters treatment. If the 2 lines 'grepped' are like this:
Code:
  Número / Data
  1001114166 x 10.11.2009
No problem, finish ok.

But if the two line are like this:
Code:
  Número / Data
  10111416 x 10.11.2009
No works!

How can I solve this?

Thank's!
 
Old 11-26-2009, 07:01 AM   #2
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
man cut

You can see that the problem is that cut is cutting the 10 characters, so if the number is only 8 chars long you are cutting 2 chars extra, right?
Just cut the characters before the first space like this:
Code:
cut -f1 -d " "
or use sed for the required purpose.
 
Old 11-26-2009, 07:24 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
the LIST=`ls` is superfluous


Code:
for i in *.pdf
do
   etc...
done
you need to explain better what you are trying to do.
what's the 10 characters about?

Last edited by bigearsbilly; 11-26-2009 at 07:27 AM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming files tekmann33 Linux - Newbie 6 05-22-2009 10:08 AM
Renaming files leupi Linux - General 5 09-16-2008 03:22 AM
help renaming files please balistic Linux - Newbie 2 07-29-2007 03:35 PM
help renaming files balistic Linux - Newbie 4 07-29-2007 08:04 AM
Renaming files TomalakBORG Linux - Newbie 2 12-05-2005 04:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:10 PM.

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