Removes the ^M character in Unix/Linux

This script removes the ^M character from the file. Mainly for those who use windows editor to edit Unix/Linux text files. I would definitely recommend VI or emacs if you are messing with Unix/Linux text files. Create a shell script file and copy paste the code below.
#!/bin/ksh
#Script to remove the ugly DOS ^M characters
 
for readfiles in $@
do
tr -d 'r' < $readfiles > $sometempfile.tmp
mv $sometempfile.tmp $readfiles
done
FacebookTwitterGoogle+Share

Unix script to find the total size of files

Create a shell script file and copy paste the code. Please let me know if you find any bugs
awk '
# filesum: list files and total size in bytes
# input: long listing produced by "ls -l"
BEGIN {
printf("%15s %s\n", "BYTES", "FILE");
}
# test for 9 fields, files begin with "-"
NF == 9 &amp;&amp; /^-/ {
++filenum;            # count files
sum += $5;            # accumulate sizes
num = sprintf("%.2f", $5);
while (num ~ /[0-9][0-9][0-9][0-9]/) {
sub(/[0-9][0-9][0-9][,.]/, ",&amp;", num);
}
sub(/\..*/, "", num);
printf("%15s %s\n", num, $9);    # print size and name
}
END {
num = sprintf("%.2f", sum);
while (num ~ /[0-9][0-9][0-9][0-9]/) {
sub(/[0-9][0-9][0-9][,.]/, ",&amp;", num);
}
sub(/\..*/, "", num);
printf("\n%15s total bytes in %d files\n\n", num, filenum);
}'