Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
find /the/dir -type f -exec sh -c "file -b '{}' | grep -q text && echo dos2unix '{}'" \;
find /the/dir -type f -exec sh -c "file '{}' | grep -w text > /dev/null && echo dos2unix '{}'" \;
-w Search for the expression as a word as if surrounded by \< and \>.
#!/bin/perl -w
use strict;
my $qflag = 0;
sub procdir ( $ )
{
my $dirname = shift;
opendir DHANDLE, $dirname or return;
foreach my $dentry ( readdir DHANDLE )
{
$dentry =~ /^\.{1,2}$/ and next;
my $fullname = $dirname . '/' . $dentry;
-f $fullname and
not_data ( $fullname ) and
has_ctrl_m ( $fullname ) and
rm_ctrl_m ( $fullname );
-d $fullname and &procdir ( $fullname );
}
closedir DHANDLE;
}
sub not_data ($)
{
my $fname = shift;
$fname =~ /\.cbl$/ and return 1;
$fname =~ /\.mk$/ and return 1;
$fname =~ /\.c$/ and return 1;
$fname =~ /\.sql/ and return 1;
my $ftype;
`file -m /etc/magic $fname` =~ /:\s+(\w+)\s+/ and $ftype = $1 or return
1;
$ftype =~ /^gzip$/ and return 0;
$ftype =~ /^PKZIP$/ and return 0;
$ftype =~ /^data$/ and return 0;
$ftype =~ /^compressed$/ and return 0;
$ftype =~ /^executable$/ and return 0;
$ftype =~ /^tar$/ and return 0;
return 1;
}
sub has_ctrl_m ( $ )
{
my $fname = shift;
my $retval = 0;
open FH, $fname or ( print "Unable to open $fname\n"), return;
while (<FH>)
{
/\r$/ and $retval = 1, last;
}
close FH;
return $retval;
}
sub rm_ctrl_m ( $ )
{
my $fname = shift;
my $tmpname = $fname . ".tmp." . $$;
$qflag or do
{
print "$fname has ctrl-Ms. Do you want to fix \(y\/n\)\n";
my $resp = <STDIN>;
$resp =~ /^y/i or return;
};
open IF, $fname or
( print "Unable to open $fname\n"), return;
open OF, ">", $tmpname or
( print "Unable to open $tmpname\n"),
close IF,
return;
while (<IF>)
{
chomp;
s/\r$//;
print OF $_, "\n";
}
close IF;
close OF;
rename $tmpname, $fname;
print "$fname fixed\n";
}
sub abort
{
print STDERR @_, "\n";
print STDERR "Usage:- fixctrlMs.pl <directory> [y]\n";
print STDERR "if the 'y' flag is used all corrections will be
automatic\n";
exit -1;
}
( $#ARGV != 0 ) && ( $#ARGV != 1 ) and abort "Invalid parameter count";
-d $ARGV[0] or abort "$ARGV[0] is not a directory";
$#ARGV == 1 && $ARGV[1] =~ /^y/i and $qflag = 1;
procdir ( $ARGV[0] );
-w Does a word search.