Skip to content

Instantly share code, notes, and snippets.

@dylan-k
Created September 12, 2013 00:55
Show Gist options
  • Save dylan-k/6531959 to your computer and use it in GitHub Desktop.
Save dylan-k/6531959 to your computer and use it in GitHub Desktop.
rename each text file according to its first line of text
#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