Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. regular expression with awk
  2. Section/TeamName/age/NAME/[Jan/Feb/Mar....etc].txt
  3.        
  4. EngineeringDepartment/TeamA/25-30/John/Jan.txt
  5.        
  6. cp EngineeringDepartment/TeamA/25-30/John/Jan.txt ./total/John/Jan.txt
  7.        
  8. #!/bin/bash
  9. find . -name "*.txt" | awk -v FS="/" '{system("mkdir -p ./total/" $5)}'
  10. 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)}'
  11.        
  12. mkdir total                                   # Example data:
  13. for file in */*/*/*/*.txt ; do                # EngDept/TeamA/25-30/John/Jan.txt
  14.    sec_team_age=$(dirname $(dirname "$file")) # EngDept/TeamA/25-30
  15.    name_month=${file#"$sec_team_age/"}        # John/Jan.txt
  16.    mkdir -p $(dirname total/$name_month)      # mkdir -p total/John
  17.    cp $file total/$name_month                 # cp $file total/John/Jan.txt
  18. done