Mayank Gour
Mayank Gour

Reputation: 136

How to access all files in all sub directories using shell script?

I want to execute following command on all files of a directory and also on all files in sub directories of that directory:

cat filename | col -b > filename

this command will remove control M or ^M character from the file and works fine with single file. Please help ... I tried below command but doesn't work. It works with single directory but not with sub directories.

for i in *
do
        cat i | col -b > i
done

Upvotes: 3

Views: 1356

Answers (2)

HD..
HD..

Reputation: 1476

find . -type f -name '*.gif or .jpeg' -o -exec sed -i 's/^M//' {} \;

this is what your looking for ^M it works in all file to remove the images. just check it in you are code

Upvotes: 1

Oliver Matthews
Oliver Matthews

Reputation: 7823

find . -type f -exec sed -i 's/^M//' {} \;

Note, do the ^M by hitting ctrl-V then ctrl-m, not just ^M If you want to only hit a subset of files, then specify an appropriate regexp and pass that to find as (most likely) -iname - see man find for the options

Upvotes: 0

Related Questions