dolibarr/dev/tools/fixduplicatelanglines.sh

39 lines
947 B
Bash
Raw Normal View History

2014-03-26 18:19:31 +01:00
#!/bin/sh
# Recursively deduplicate file lines on a per file basis
# Useful to deduplicate language files
#
# Needs awk 4.0 for the inplace fixing command
#
# Raphaël Doursenaud - rdoursenaud@gpcsolutions.fr
# Syntax
if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
then
2015-03-13 16:20:42 +01:00
echo "Find exact duplicated lines into file (not cross file checking)"
echo "Usage: deduplicatefilelinesrecursively.sh [list|fix]"
fi
# To detect
if [ "x$1" = "xlist" ]
then
2016-10-11 10:24:02 +02:00
echo "Search duplicate line for lang en_US"
2015-03-13 16:20:42 +01:00
for file in `find htdocs/langs/en_US -type f -name *.lang`
do
2015-03-13 16:20:42 +01:00
if [ `sort "$file" | grep -v '^$' | uniq -d | wc -l` -gt 0 ]
then
2015-03-13 16:20:42 +01:00
echo "***** $file"
sort "$file" | grep -v '^$' | uniq -d
fi
done
fi
# To fix
if [ "x$1" = "xfix" ]
then
2016-10-11 10:24:02 +02:00
echo "Fix duplicate line for lang en_US"
2015-03-13 16:20:42 +01:00
for file in `find htdocs/langs/en_US -type f -name *.lang`
do
awk -i inplace ' !x[$0]++' "$file"
done;
fi