Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to pass to pdftk, a list of arguments constituted by strings repeated twice like:

A1-2 B1-2 A3-4 B3-4 A5-6 B5-6... and so on...

I managed to achieve this with this workaround

for ((x=1, y=2;x>=18, y<=18;x++, y++)); do echo "A$x-$y B$x-$y "; done| awk 'NR %2==1 {print $1, $2} ' | tr '\n' ' '

that gives:

A1-2 B1-2 A3-4 B3-4 A5-6 B5-6 A7-8 B7-8 A9-10 B9-10 A11-12 B11-12 A13-14 B13-14 A15-16 B15-16 A17-18 B17-18

but I'm unsatisfied, and I'm looking for a proper , more elegant and better way to perform this task

share|improve this question
up vote 5 down vote accepted
for ((x=1; x<=18; x+=2)); do echo -n "A$x-$((x+1)) B$x-$((x+1)) "; done
share|improve this answer
so simple! Many thanks! – Dingo Apr 11 '12 at 12:27
You can even use 2 variables, as in C: for (( x=1, y=2; x<=18; x+=2, y+=2 )); do printf "A%d-%d B%d-%d " $x $y $x $y; done – glenn jackman Apr 11 '12 at 13:12

or even pure awk:

awk 'BEGIN {for (i=1; i<19; i+=2) printf "A"i"-"i+1 " B"i"-"i+1" "}'
share|improve this answer
+1 for portability – Michał Šrajer Apr 11 '12 at 15:31

With just bash:

pdftk input.pdf cat $(for ((x=1; x<18; x+=2)); do echo {A,B}$x-$((x+1)); done) output output.pdf

With GNU utilities (Linux or Cygwin):

pdftk input.pdf cat $(seq 1 2 17 | awk '{$1 = $1 "-" ($1+1); print "A" $1; print "B" $1}') output output.pdf

With Perl:

pdftk input.pdf cat $(perl -e 'print map {"A$_ B$_ "} map {(2*$_-1) . "-" . (2*$_)} (1..9)') output output.pdf
share|improve this answer
+1 for offering valuable alternative one-liners. Maybe it would be worth considering to add xargs in order to not have too many arguments error, if number of strings becomes very big (100 or 200 or more) – Dingo Apr 11 '12 at 22:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.