Adequately order the page numbers to print a booklet

F=136; [[ $(($F % 4)) == 0 ]] && for i in $(seq 1 $(($F/4))); do echo -n $(($F-2*($i-1))),$((2*$i-1)),$((2*$i)),$(($F-2*$i+1)),; done | sed 's/,$/\n/' || echo "Make F a multiple of 4."
Useful if you don't have at hand the ability to automatically create a booklet, but still want to. F is the number of pages to print. It *must* be a multiple of 4; append extra blank pages if needed. In evince, these are the steps to print it, adapted from https://help.gnome.org/users/evince/stable/duplex-npage.html.en : 1) Click File ▸ Print. 2) Choose the General tab. Under Range, choose Pages. Type the numbers of the pages in this order (this is what this one-liner does for you): n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11... ...until you have typed n-number of pages. 3) Choose the Page Setup tab. - Assuming a duplex printer: Under Layout, in the Two-side menu, select Short Edge (Flip). - If you can only print on one side, you have to print twice, one for the odd pages and one for the even pages. In the Pages per side option, select 2. In the Page ordering menu, select Left to right. 4) Click Print.
Sample Output
136,1,2,135,134,3,4,133,132,5,6,131,130,7,8,129,128,9,10,127,126,11,12,125,124,13,14,123,122,15,16,121,120,17,18,119,118,19,20,117,116,21,22,115,114,23,24,113,112,25,26,111,110,27,28,109,108,29,30,107,106,31,32,105,104,33,34,103,102,35,36,101,100,37,38,99,98,39,40,97,96,41,42,95,94,43,44,93,92,45,46,91,90,47,48,89,88,49,50,87,86,51,52,85,84,53,54,83,82,55,56,81,80,57,58,79,78,59,60,77,76,61,62,75,74,63,64,73,72,65,66,71,70,67,68,69

1
By: Kayvlim
2014-06-11 01:21:08

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: