首先,您必须逐个读取日志文件中的行。
第二步,在两个变量中获取行中的第一个和第二个字段。
第三,使用BASH/Shell中的case/esac语句来处理要移动的新位置。
#!/bin/bash
while read line
do
#Get first column/field - path
from="$(echo $line | cut -d' ' -f1)"
firstfolder="$(echo $from | cut -d'/' -f1)"
#Get Second column - number
number="$(echo $line | cut -d' ' -f2)"
case $num in
1)
#When number is 1. I'll do this. This assumes you aleady
#where $firstfolder exists.
mv $firstfolder new_directory1
2)
#When number is 2. I'll do that. This assumes you aleady
#where $firstfolder exists.
mv $firstfolder new_directory2
3)
#When number is 3. I'll do this/that. This assumes you aleady
#where $firstfolder exists.
mv $firstfolder new_directory3
#4) ..
#5) ..
#..) ..
#9) ..
*)
#This is when number is not between 1 - 9.
echo "-- oh oh, I got you a dollar !!! - File: $first"
esac
done < someTextLogFile.txt
欲了解更多信息,请在线学习BASH。
如何使用case语句的一个好例子是:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_03.html