DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 26th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default run same command many times with diff args

Hello
I need to delete some pages from quite a few .djvu files. The problem is the djvm command only accepts one page, no page ranges. So, how do I run the same command but increasing by one every time until a certain number?
The djvm command looks like this:
Code:
djvm -d file.djvu pagenumber
If I need to delete, say, page 1 to 10, how do I tell the script to increase the pagenumber until it reaches 10?
Reply With Quote
  #2   (View Single Post)  
Old 26th May 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

Code:
for page in `jot 10 1`
do
djvm -d file.djvu $page
done
Reply With Quote
  #3   (View Single Post)  
Old 26th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default

thanks DutchDaemon.
Actually, now that I think of it, I could simply run the same program 10 times, since the pages I need to delete are all at the beginning of the file.
But learned something new, which is good
Reply With Quote
  #4   (View Single Post)  
Old 26th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default

uhm, actually, I've tried your command, but it does not seem to do the job
Reply With Quote
  #5   (View Single Post)  
Old 26th May 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

Not using bash or sh, I guess. You can do this from (t)csh by first typing [sh][enter] and then entering those commands.
Reply With Quote
  #6   (View Single Post)  
Old 26th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default

yes, I'm using ksh, the default shell in openbsd.
Actually I've read quite a few articles on the web on the subject, but still cannot appreciate the difference between shells. Probably because I don't really do any serious programming.

Anyway, it does not work even from sh. With this command it deletes only the first page:
Code:
for page in `jot 3 1` ; do djvm -d file.djvu $page ; done
Reply With Quote
  #7   (View Single Post)  
Old 26th May 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

Weird. Is OpenBSD's jot different from FreeBSD's?

Code:
for page in `jot 3 1` ; do echo $page ; done
1
2
3
Reply With Quote
  #8   (View Single Post)  
Old 26th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default

with the echo command I get the same as you, but it does not work on the real file, could it be a problem with the djvm command?

Well well, I'd better get some sleep now
Reply With Quote
  #9   (View Single Post)  
Old 26th May 2009
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,067
Thanked 198 Times in 156 Posts
Default

The command
% jot 10 1

Should output

Code:
1 2 3 4 5 6 7 8 9 10
So it is easy to test if jot(1) is the culprit.

Testing the djvm command is also simple:
% djvm -d file.djvu n
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Old 26th May 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,141
Thanked 182 Times in 149 Posts
Default

For command substitution I prefer to use the the "$( .... )" construct instead of the archaic backquotes ` ..... ` format.
Code:
for page in $(jot 3 1) ; do echo $page ; done 
1
2
3
BTW this is on OpenBSD
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Old 26th May 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

Old habits ... In fact, I rewrote all my old scripts to the $() way not too long ago
Reply With Quote
Old 26th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default

well, I've tried it again, it echoes page 1 2 3 but then when cheching the file it only deleted one page.
Reply With Quote
Old 26th May 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

Quote:
djvm -d[elete] doc.djvu pagenum
What does 'pagenum' actually mean in this context? A literal page number (as in: printed on a page), or 'the number of pages to delete' or something. I have a feeling that when you delete 'page 1', the remaining pages shift one position (like arguments in a shell script), so that there will always be a 'page 1' (even when it was 'page 2' one deletion earlier). Maybe 'page 1' means 'the first page on the stack', not literally 'page with the number one printed on it'. What happens when you use this command with the number 1 ten times in a row?

Then again, it might snow in the Sahara right now.
Reply With Quote
Old 26th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default

the page number means the actual page number according to the djvu order (like in a pdf file, the thumbnails are ordered 1 2 3 etc, but on the actual picture the number might be different). If I run djvm with pagenumber 3, it will delete the third image, and of course, after deleting it, the fourth image will have become the third etc.
Anyway, I've solved it running n times the command on page one. It was a way to learn some more scripting. Very bad that this djvm command does not support page ranges...
Reply With Quote
Old 27th May 2009
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
 
Join Date: May 2008
Posts: 194
Thanked 47 Times in 22 Posts
Default

Quote:
Originally Posted by gosha View Post
the page number means the actual page number according to the djvu order (like in a pdf file, the thumbnails are ordered 1 2 3 etc, but on the actual picture the number might be different). If I run djvm with pagenumber 3, it will delete the third image, and of course, after deleting it, the fourth image will have become the third etc.
Anyway, I've solved it running n times the command on page one. It was a way to learn some more scripting. Very bad that this djvm command does not support page ranges...
I'm not familiar with djvm, but maybe:
Code:
#!/bin/sh
count=1
until [ $count -gt 10 ]; do
          djvm -d file.djvu 1
          count=`$count + 1`
done
That would delete (or wathever) first 10 pages (if the pages change the way you described).
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn.
If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD
Reply With Quote
Old 27th May 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

Quote:
Originally Posted by gosha View Post
the page number means the actual page number according to the djvu order (like in a pdf file, the thumbnails are ordered 1 2 3 etc, but on the actual picture the number might be different). If I run djvm with pagenumber 3, it will delete the third image, and of course, after deleting it, the fourth image will have become the third etc.
Anyway, I've solved it running n times the command on page one. It was a way to learn some more scripting. Very bad that this djvm command does not support page ranges...
Ok, so you could simply run
Code:
for i in $(jot 10 1) ; do djvm -d file.djvu 1 ; done
Looks weird, but it'll work
Reply With Quote
Old 27th May 2009
gosha gosha is offline
Spam Deminer
 
Join Date: Jun 2008
Location: China
Posts: 256
Thanked 0 Times in 0 Posts
Default

thanks you all
I did already use DutchDaemon's solution. If you remember you gave it to me some time ago to run it on .tex files. If I understan properly s0xxx 's solution does exactly the same thing.
Reply With Quote
Old 27th May 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

Right. Sure. There's always more than one way
Reply With Quote
Old 27th May 2009
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 557
Thanked 14 Times in 13 Posts
Default

Quote:
Code:
count=`$count + 1`
Or did you mean:
Code:
count=`expr $count + 1`
?
Reply With Quote
Old 28th May 2009
fbsduser fbsduser is offline
Shell Scout
 
Join Date: Aug 2008
Posts: 104
Thanked 4 Times in 4 Posts
Default

Quote:
Originally Posted by Carpetsmoker View Post
The command
% jot 10 1

Should output

Code:
1 2 3 4 5 6 7 8 9 10
So it is easy to test if jot(1) is the culprit.

Testing the djvm command is also simple:
% djvm -d file.djvu n
This is the results of the "jot" command under M$Linux
Code:
 
Ghost*Rider@CrackBox-X64:~$  jot 10 1
1
2
3
4
5
6
7
8
9
10
Ghost*Rider@CrackBox-X64:~$
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sparc ultra 5 ok== files and args ??? philo_neo71 FreeBSD Installation and Upgrading 2 21st September 2009 03:43 AM
repeat same command n times gosha Programming 8 12th March 2009 11:25 PM
Passing args to port / make while installing apache robot FreeBSD Ports and Packages 2 27th August 2008 01:55 PM
Thanked X times in X posts johnlvs2run Feedback and Suggestions 6 18th May 2008 01:21 PM
Daemonforums very slow, times out a lot Weaseal Feedback and Suggestions 15 16th May 2008 12:44 AM


All times are GMT. The time now is 11:12 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick