Редагування сторінок підручника/man encode converter.sh

Матеріал з docs.linux.org.ua — збірника документації з Unix/Linux українською мовою.

Перейти до: навігація, пошук
# !/bin/bash
# 20051123 man_encode_converter.sh hse@ukr.net http://docs.linux.org.ua/dlou/index.php/Man
# Distributed under the terms of the GNU General Public License v2 or later

# This script convert installed man page from one encoding to another.

# Edit to suite yours configuration:
# Man path:
manpath=/usr/share/man/ru
# From which encoding:
fromencode='koi8-r'
# To which encoding
toencode='utf8'
# If some page was compressed which archivator and how to use and what extensions they have:
archivator='/bin/gzip -dq'
ext='gz'

for i in  1 2 3 4 5 6 7 8 9 0p 1p 3p n s
  do
	if [ -d $manpath/man$i ]
	  then
		cd $manpath/man$i/
		for j in `ls $manpath/man$i`
		  do
			if [[ `echo $j |awk -F'.' '{print $3}'` == "$ext" || `echo $j |awk -F'.' '{print $4}'` == "$ext" || `echo $j |awk -F'.' '{print $5}'` == "$ext" ]]
			  then
				file=`echo $j |awk -F'.' '{print $1}'`.`echo $j |awk -F'.' '{print $2}'`
				if [[ `echo $j |awk -F'.' '{print $3}'` != "$ext" ]]
				  then
					file=$file.`echo $j |awk -F'.' '{print $3}'`
					if [[ `echo $j |awk -F'.' '{print $4}'` != "$ext" ]]
					  then
						file=$file.`echo $j |awk -F'.' '{print $4}'`
					fi
				fi
				($archivator $manpath/man$i/$j)
				(cat $manpath/man$i/$file |iconv -f $fromencode -t $toencode > $manpath/tmp)
				mv -f $manpath/tmp $manpath/man$i/$file
				bzip2 -zf9 $manpath/man$i/$file
			  else
			  	(cat $manpath/man$i/$j |iconv -f $fromencode -t $toencode > $manpath/tmp)
				mv -f $manpath/tmp $manpath/man$i/$j
			fi
		  done
	fi
  done

exit 0
Особисті інструменти