Skip to main content
added 173 characters in body
Source Link
bxm
  • 5.2k
  • 1
  • 22
  • 26

Assuming that your directories are named exactly as you say, are in the current directory, and don't contain thousands of files each, something like this should work:

for dir in P{1..60}/{A,M} ; do
  [ -d "$P" ] || continue
  cp "$dir"/* "${dir%[AM]}out/"
done

Using the * wildcard to select your directories may work but risks over matching and changing things you don’t expect.

This should only match the exact set of items you describe, but as such it is quite specific to the case you describe, and the approach may need to be modified for different input.

If you have file name clashes in your two directories the contents from M will replace that from A. This could be handled, but wasn't in your original specification.

Assuming that your directories are named exactly as you say, are in the current directory, and don't contain thousands of files each, something like this should work:

for dir in P{1..60}/{A,M} ; do
  [ -d "$P" ] || continue
  cp "$dir"/* "${dir%[AM]}out/"
done

Using the * wildcard to select your directories may work but risks over matching and changing things you don’t expect.

This should only match the exact set of items you describe, but as such it is quite specific to the case you describe, and the approach may need to be modified for different input.

Assuming that your directories are named exactly as you say, are in the current directory, and don't contain thousands of files each, something like this should work:

for dir in P{1..60}/{A,M} ; do
  [ -d "$P" ] || continue
  cp "$dir"/* "${dir%[AM]}out/"
done

Using the * wildcard to select your directories may work but risks over matching and changing things you don’t expect.

This should only match the exact set of items you describe, but as such it is quite specific to the case you describe, and the approach may need to be modified for different input.

If you have file name clashes in your two directories the contents from M will replace that from A. This could be handled, but wasn't in your original specification.

Source Link
bxm
  • 5.2k
  • 1
  • 22
  • 26

Assuming that your directories are named exactly as you say, are in the current directory, and don't contain thousands of files each, something like this should work:

for dir in P{1..60}/{A,M} ; do
  [ -d "$P" ] || continue
  cp "$dir"/* "${dir%[AM]}out/"
done

Using the * wildcard to select your directories may work but risks over matching and changing things you don’t expect.

This should only match the exact set of items you describe, but as such it is quite specific to the case you describe, and the approach may need to be modified for different input.