I want to produce a following list of pages (for imposition work); (number of pages is variable, but I make a sample of my needs using a list of 16 pages, logic is the same for longer lists)
1,16
8,9
15,2
10,7
3,14
6,11
13,4
12,5
I written this for cycle:
for ((x=16, y=1, z=8, w=9;x>=4, y<=4, z>=12, w<=12;x--, y++, z--, w++)); do echo "$x $y;$z $w"; done | tr ";" "\n" | tr " " ","
that, however, produces:
16,1
8,9
15,2
7,10
14,3
6,11
13,4
5,12
and not the list of pages I want. So, I need, with awk or other commands, to swap fields in some columns following this pattern (repeating every 4 couple of pages)
swap fields
no swap fields
no swap fields
swap fields
16,1 (swap: becomes: 1,16
8,9 (no swap: remains 8,9
15,2 (no swap: remains 15,2
7,10 (swap: becomes: 10,7
14,3 (swap: becomes: 3,14
6,11 (no swap: remains 6,11
13,4 (no swap: remains 13,4
5,12 (swap: becomes: 12,5
generalizing the logic of this imposition (I need to impose a single copy of an A6 book across an A4 page format) I wrote a more generalized script
#!/bin/sh
pages=$1
halfpages="`let DIVISION=$pages/2; echo $DIVISION`"
incr="$(echo "scale=0; $halfpages+1" |bc -l)"
dividedby4="$(echo "scale=0; $pages/4" |bc -l)"
lastupperpage="$(echo "scale=0; $pages-$dividedby4" |bc -l)"
u="u"
for ((x=$pages, y=1, z=$halfpages, w=$incr;x>=4, y<=4, z>=$lastupperpage, w<=$lastupperpage;x--, y++, z--, w++)); do echo "$x$u $y$u;$z $w"; done | tr ";" "\n" | tr " " "," | tr "\n" ","
exit 0
however I'm only able to produce:
16u,1u,8,9,15u,2u,7,10,14u,3u,6,11,13u,4u,5,12
instead of right:
1u,16u,8,9,15u,2u,10,7,3u,14u,6,11,13u,4u,12,5
that I pass to Multivalent.jar
I attach a picture of right imposition of an A6 across an A4 to show the right sequence of imposition
what I try to obtain is a way to impose a whole A6 book across an A4 page in ONE signature consisting in all its pages (not the 8-Page Imposition), in order to cut at half A4 page, close the two halves one over another, reverse sheet obtained, cut at half and applying glue to left edge in order to apply cover
to perform this task I need or to rethink my script from scratch or find a way to swap fields in columns by a fixed pattern (swap, no swap, no swap, swap) in order to correct wrong order produced by my script
EDIT
solved sending standard output of script to awk with this syntax:
awk -F "," '{
print $2 "," $1;
getline; print;
getline; print;
getline; print $2 "," $1
}'
1u,16u,8,9,15u,2u,10,7,3u,14u,6,11,13u,4u,12,5
directly.