Created
September 12, 2013 00:55
-
-
Save dylan-k/6531959 to your computer and use it in GitHub Desktop.
rename each text file according to its first line of text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A shell script that will rename all the text files in a directory | |
#each file will be named with the first line of text from that file | |
for file in * | |
do | |
# Avoid renaming diretories! | |
if [ -f "$file" ] | |
then | |
newname=`head -1 $file` | |
if [ -f "$newname" ] | |
then | |
echo "Cannot rename $file to $newname - file already exists" | |
else | |
mv "$file" "$newname" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment