I am using sed to do a bunch of changes to files. I think the question is relevant for any operation that want to iterate through files that match a pattern and include subdirectories both in the original file search recursion AND (i.e. creating them to replicate the structure) in the file creation output
I initially get the files with
mkdir -p _seded for file in *_spec.rb do cat $file ... a bunch of seds > _seded $file end
How can I get the files plus subdirectories of files that match the pattern?
For instance if I have
spec/ex1 spec/ex2_spec.rb spec/subs/subex1 spec/subs/subex1_spec.rb spec/subs/subex2/aaa spec/subs/subex3/s3_spec.rb spec/subs/subex4/s4.rb spec/subs/subex4/bbb
then I should get:
_seded/ex2_spec.rb _seded/subs/subex1_spec.rb _seded/subs/subex3/s3_spec.rb
Note: directories subex2 and subex4 should not be created as they would be empty.
mkdir -p _seded find . -name '*_spec.rb' | xargs cat | sed -e '[/pattern/replace code]' > _seded/$file
but got errors like:
$ ./convert_should_to_expect.sh ./convert_should_to_expect.sh: line 5: _seded/: Is a directory xargs: cat: terminated by signal 13 now doing its !!! sed: couldn't edit _seded/: not a regular file awk: cmd. line:1: fatal: cannot open file `_seded/' for reading (Is a directory) mv: `_seded/tmp' and `_seded/tmp' are the same file sed: couldn't edit _seded/: not a regular file sed: couldn't edit _seded/: not a regular file