Skip to content

Instantly share code, notes, and snippets.

@mohammad-haji
Created May 26, 2018 13:01
Show Gist options
  • Save mohammad-haji/9588e218d3d7afbe015eb3903cc5065d to your computer and use it in GitHub Desktop.
Save mohammad-haji/9588e218d3d7afbe015eb3903cc5065d to your computer and use it in GitHub Desktop.
#!/bin/bash
: '
copy files from source directory into another directory by file index
@usage: ./cp.sh sourcePath targetPath
@example: ./cp.sh ./original/ ./cpfolder/
'
sourcePath=$1;
targetPath=$2;
if [[ (-z "$sourcePath") || (-z "$targetPath") ]];
then
echo "wrong input";
echo "define source path like: $./cp.sh sourcePath targetPath"
exit 0;
else
numFiles=`find $sourcePath -type f | wc -l`;
echo "Number of Files in current directory: "$numFiles;
echo "Enter start index of files to cut:";
read startIndex;
echo "Enter end index of files to cut:";
read endIndex;
if [[("$startIndex" -gt 0) && ("$endIndex" -le "$numFiles")]];
then
echo "copy from " $startIndex " till " $endIndex;
for i in $(seq $startIndex $endIndex);
do
cp $sourcePath/text-$i.txt $targetPath
echo "file" $sourcePath"text-"$i.txt "copid to " $targetPath;
done
else
echo "Wrong Input, start index should be a number in 1..."$numFiles " range"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment