Some Useful Scripts
Posted on August 13, 2010 | Stephen
I am always searching for some simple scripts to make my life easier. Here are a few that I have used.
This script removes the spaces from file names and directories. It replaces them with the underscore "_". It must be run several times due to the changes in `find` when a directory name has changed.
This script I have used to concatenate large numbers of ascii text files. It adds a column for the file name so the final output file has a reference back to the original file.
This script removes the spaces from file names and directories. It replaces them with the underscore "_". It must be run several times due to the changes in `find` when a directory name has changed.
#!/bin/sh
find . -name '* *' | while read file;
do
target=`echo "$file" | sed 's/ /_/g'`;
echo "Renaming '$file' to '$target'";
mv "$file" "$target";
done;
This script I have used to concatenate large numbers of ascii text files. It adds a column for the file name so the final output file has a reference back to the original file.
#!/bin/sh
for i in `ls *.[Rr][Ss][Ff]`
do
awk '{print "\"" FILENAME "\"\t" "\"xxx\"" "\t" $0}' $i >> outfile.txt
done
