1

I'm finding myself having to do this every once in a while, and was wondering if there's a way to simplify this command?

In essence, all I'm doing is copying a file and re-naming it. The functionality to create A1, A2.. B1, B2.. is non-negotiable :) Thus, the nested for loop.

Note, I'm not interested in creating an actual script file. I need something quick and dirty.

bash> for x in {A..B}; do for i in {1..4};do cp orig.xml prefix_$x$i.xml; done;done

System Info

Platform: SunOS

Bash Version: GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.10)

Kent
  • 189,393
  • 32
  • 233
  • 301
Roberto Navarro
  • 948
  • 4
  • 16
  • 2
    This seems simple enough, quick enough and dirty enough. The only simplification is either a script or an alias. – Olaf Dietsche Feb 22 '13 at 17:11
  • Good point on the alias. Only problem is that I'm sometimes not personally logged into the system. Thanks tho, I was hoping someone more creative than I could do this quicker :) – Roberto Navarro Feb 22 '13 at 17:16
  • This would be a script or some shortcut file, where you can cut and paste from one xterm to another. – Olaf Dietsche Feb 22 '13 at 17:19
  • 1
    Well, since you concatenate the two variables, you could do `for x in {A..B}{1..4}; do cp orig.xml prefix_${x}.xml;done`, which is a bit shorter. But, if you ever need the variables in different places, the nested loop is probably better... – twalberg Feb 22 '13 at 17:42
  • @OlafDietsche it could be more simple and more dirty. more quick? I don't know however.. – Kent Feb 22 '13 at 17:49
  • @twalberg urr haven't seen your comment... I was testing it on the Sun server to make sure it works on bash 3.0.... :( – Kent Feb 22 '13 at 17:55

1 Answers1

5

it has still room to be simplified, for example

for x in {A..B}{1..4}; do cp orig.xml prefix_$x.xml; done;

this works on platform:

SunOS 5.10 Generic_147441-12 i86pc i386 i86pc

GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.10)
Kent
  • 189,393
  • 32
  • 233
  • 301