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,168,915,210,73,146,1113,412,5I 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,18,915,27,1014,36,1113,45,12and 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 fieldsno swap fieldsno swap fieldsswap fields16,1 (swap: becomes: 1,168,9  (no swap: remains 8,915,2 (no swap: remains 15,27,10 (swap: becomes: 10,714,3 (swap: becomes: 3,146,11 (no swap: remains 6,1113,4 (no swap: remains 13,45,12 (swap: becomes: 12,5generalizing 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/shpages=$1halfpages=`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=ufor ((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 0however I'm only able to produce:16u,1u,8,9,15u,2u,7,10,14u,3u,6,11,13u,4u,5,12instead of right:1u,16u,8,9,15u,2u,10,7,3u,14u,6,11,13u,4u,12,5that I pass to Multivalent.jarhttp://ifile.it/iqpjo4s/Multivalent.jarI attach a picture of right imposition of an A6 across an A4 to show the right sequence of impositionwhat 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 coverto 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 scriptEDITsolved sending standard output of script to awk with this syntax:awk -F , '{    print $2 , $1;    getline; print;    getline; print;    getline; print $2 , $1}' 
swapping fields in columns by fixed pattern (yes, no, no, yes)
bash;awk;numbering
The following script is a much cleaner way of obtaining the output you want.#!/usr/bin/env bash(($# == 0)) && {    echo Usage: $0 <page_count>    exit 1} >&2# nTotal = $1 rounded up to a multiple 8nTotal=$(($1 + 7))nTotal=$((nTotal - nTotal % 8))nHalf=$((nTotal / 2))nQuarter=$((nTotal / 4))# print page numbers in groups of 4, 2 groups at a timefor ((x=0; x < nQuarter; x+=2)); do    printf '%du,%du\n%d,%d\n' \        $((x + 1)) $((nTotal - x)) $((nHalf - x)) $((nHalf + x + 1))    printf '%du,%du\n%d,%d\n' \        $((nTotal - (x + 1))) $((x + 2)) \        $((nHalf + x + 2)) $((nHalf - x - 1))doneExample$ ./imposition8 161u,16u8,915u,2u10,73u,14u6,1113u,4u12,5I rewrote your script because there were several problems with the original.You used non-sh compatible bash specific syntax, so I corrected the shebang line to match.The entire thing can be done in pure bash.  The use of multiple tr invocations, an external awk, and bc is inefficient.  In particular, you should know that bash and even POSIX-compliant sh can do math internally.