Question : Need a script to traverse my files check for tabs replace tabs with spaces!!

Hi all

What do I do to get list of files that have tabs? How to do substitute the tabs with spaces?
Is there a way to do that in a perl script that traverse the directory structure and replace tabs with spaces?


my project has so many files it would be time consuming to do one by one!


Thanks
in advance!

Answer : Need a script to traverse my files check for tabs replace tabs with spaces!!

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
#!/usr/bin/perl
 
$dir = "path";
 
use File::Find;
find(sub{push(@files, $File::Find::name) unless -d}, $dir);
 
foreach $file (@files) {
        open(FILE, $file);
        foreach $line () { push(@file, $line); }
        close(FILE);
 
        $data = join("", @file);
        @file = ();
 
        $data =~ s/\t/ /g;
        open(FILE, "> $file");
        print FILE $data;
        close(FILE);
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us