0

The title is rather more simplified than the functionality I am trying to express in a script.

I have a one-level deep directory tree (much bigger than example) which contain various content, although only two particular files are of interest to me. A file called 'current' and another called 'revisions'

- foo
   |
   |-> current

- bar
   |
   |-> current
   |-> revisions

- baz
   |
   |-> not-affected

The script in mind would be triggered from the parent directory to foo/bar/baz and it would perform the following

  1. Scan all subdirectories
  2. When it finds a directory containing 'current' it will

    1. Append the content of 'current' onto revisions 'cat ${pwd}/current >> ${pwd}/revisions '
  3. Directories not containing a file named 'current' are to remain unaffected
j pimmel
  • 11,617
  • 6
  • 33
  • 43

2 Answers2

1

If it's one level deep, this should work:

for c in */current; do cat ${c} >> ${c%%current}revisions; done
David Z
  • 128,184
  • 27
  • 255
  • 279
1
for i in */current; do
  cat "${i}" >> "{i%/*}/revisions"
done

Note that this will create revisions if it doesn't exist.

brian-brazil
  • 31,678
  • 6
  • 93
  • 86