tags:

views:

1620

answers:

2

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
+1  A: 

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

for c in */current; do cat ${c} >> ${c%%current}revisions; done
David Zaslavsky
+1  A: 
for i in */current; do
  cat "${i}" >> "{i%/*}/revisions"
done

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