
Untitled
By: a guest on
May 6th, 2012 | syntax:
None | size: 0.87 KB | hits: 11 | expires: Never
regular expression with awk
Section/TeamName/age/NAME/[Jan/Feb/Mar....etc].txt
EngineeringDepartment/TeamA/25-30/John/Jan.txt
cp EngineeringDepartment/TeamA/25-30/John/Jan.txt ./total/John/Jan.txt
#!/bin/bash
find . -name "*.txt" | awk -v FS="/" '{system("mkdir -p ./total/" $5)}'
find . -name total -prune -o -type f -name "*.txt" -print | awk -v FS="/" '{src = $1 "/" $2 "/" $3 "/" $4 "/" $5 "/" $6; dst = "./total/" $5; system("cp " src " " dst)}'
mkdir total # Example data:
for file in */*/*/*/*.txt ; do # EngDept/TeamA/25-30/John/Jan.txt
sec_team_age=$(dirname $(dirname "$file")) # EngDept/TeamA/25-30
name_month=${file#"$sec_team_age/"} # John/Jan.txt
mkdir -p $(dirname total/$name_month) # mkdir -p total/John
cp $file total/$name_month # cp $file total/John/Jan.txt
done