Skip to content

Instantly share code, notes, and snippets.

@martinbpeters
Created November 26, 2010 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbpeters/716446 to your computer and use it in GitHub Desktop.
Save martinbpeters/716446 to your computer and use it in GitHub Desktop.
Simple file renaming using a loop in shell
#!/bin/sh
#
# Create a list of all txt files
# Loop over all files
# Extract name (split on '_')
# Copy file to new extension (text)
#
files=`ls -l *.txt | awk '{print $9}'`
for f in ${files}
do
echo $f
f_id=`echo $f | awk '{split($0,a,"_"); print a[1]}'`
echo $f_id
cp $f $f_id.text
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment