fixduplicatelanglines.sh 947 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. echo "Search duplicate line for lang en_US"
  18. for file in `find htdocs/langs/en_US -type f -name *.lang`
  19. do
  20. if [ `sort "$file" | grep -v '^$' | uniq -d | wc -l` -gt 0 ]
  21. then
  22. echo "***** $file"
  23. sort "$file" | grep -v '^$' | uniq -d
  24. fi
  25. done
  26. fi
  27. # To fix
  28. if [ "x$1" = "xfix" ]
  29. then
  30. echo "Fix duplicate line for lang en_US"
  31. for file in `find htdocs/langs/en_US -type f -name *.lang`
  32. do
  33. awk -i inplace ' !x[$0]++' "$file"
  34. done;
  35. fi