fixduplicatelines.sh 860 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. # Recursively deduplicate file lines on a per file basis
  3. # Useful to deduplicate language files
  4. #
  5. # Needs awk 4.0 for the inplace fixing command
  6. #
  7. # Raphaël Doursenaud - rdoursenaud@gpcsolutions.fr
  8. # Syntax
  9. if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
  10. then
  11. echo "Find exact duplicated lines into file (not cross file checking)"
  12. echo "Usage: deduplicatefilelinesrecursively.sh [list|fix]"
  13. fi
  14. # To detect
  15. if [ "x$1" = "xlist" ]
  16. then
  17. for file in `find htdocs/langs/en_US -type f -name *.lang`
  18. do
  19. if [ `sort "$file" | grep -v '^$' | uniq -d | wc -l` -gt 0 ]
  20. then
  21. echo "***** $file"
  22. sort "$file" | grep -v '^$' | uniq -d
  23. fi
  24. done
  25. fi
  26. # To fix
  27. if [ "x$1" = "xfix" ]
  28. then
  29. for file in `find htdocs/langs/en_US -type f -name *.lang`
  30. do
  31. awk -i inplace ' !x[$0]++' "$file"
  32. done;
  33. fi