Scripts ZSH

Doc : http://zsh.sourceforge.net/Doc/Release/zsh.htmlhttp://www.zzapper.co.uk/zshtips.html  http://www.refining-linux.org/

~/bin/htutf8-saccent
#!/bin/sh
# accents tex
# cat f1.html |saccent >f2.html
sed -e "s/é/\\é/g" |sed -e 's/è/\è/g' |sed -e 's/à/\à/g' |sed -e 's/ù/\ù/g' |sed -e 's/ç/\ç/g' |sed -e 's/ê/\ê/g' |sed -e 's/î/\î/g' |sed -e 's/û/\û/g' |sed -e 's/â/\â/g' |sed -e 's/ô/\ô/g' |sed -e 's/ë/\ë/g' |sed -e 's/ü/\ü/g' |sed -e 's/ï/\ï/g' |sed -e 's/ö/\ö/g'


~/bin/accent_utf-8
#!/bin/sh
# retablissement des accents
# cat f1.tex |accent >f2.tex
sed -e "s/\\\'e/é/g" |sed -e 's/\\`e/è/g' |sed -e 's/\\`a/à/g' |sed -e 's/\\`u/ù/g' |sed -e 's/\\c{c}/ç/g' |sed -e 's/\\\^e/ê/g' |sed -e 's/\\\^\\i /î/g' |sed -e 's/\\\^u/û/g' |sed -e 's/\\\^a/â/g' |sed -e 's/\\\^o/ô/g' |sed -e "s/\\\'{e}/é/g" |sed -e 's/\\`{e}/è/g' |sed -e 's/\\`{a}/à/g' |sed -e 's/\\`{u}/ù/g' |sed -e 's/\\c{c}/ç/g' |sed -e 's/\\\^{e}/ê/g' |sed -e 's/\\\^{\\i}/î/g' |sed -e 's/\\\^{u}/û/g' |sed -e 's/\\\^{a}/â/g' |sed -e 's/\\\^{o}/ô/g' |sed -e 's/\\\"u/ü/g' |sed -e 's/\\\"{u}/ü/g' |sed -e 's/\\\"\\i [ ]*/ï/g' |sed -e 's/\\\"{\\i}/ï/g' |sed -e 's/\\\"e/ë/g' |sed -e 's/\\\"o/ö/g' |sed -e 's/\\\"{o}/ö/g' |sed -e 's/\\\"{e}/ë/g' |sed -e 's/\\\^i/î/g' |sed -e 's/\\\^{i}/î/g'

~/bin/del-log-aux-synctex.txt
#! /bin/zsh
foreach i in {aux,log,synctex.gz,out,nav,snm,toc}
 rm *"."$i
 end

~/scan/prog1
#! /bin/zsh
# usage './prog1 lp10 [dir]' ou './prog1 bibl [dir]'

if (test $1"" != "bibl" -a $1"" != "lp10") then
 echo "usage 'prog1 bibl [dir]' ou 'prog1 lp10 [dir]'"
else

#nbre de messages dans le dossier mail ~/mail/scan +1
#n=`cat $HOME"/mail/scan_"$1 |grep "From:" |wc -l`
n=98
if (test $n -lt 2) then
 echo "Pas de messages dans le dossier "$HOME"/mail/scan_"$1
else

dir=$2
if (test $dir"" = "") then dir="./";fi
if (test -e $dir -a ! -d $dir) then echo $dir" existe et n\'est pas un repertoire"
else

if (test ! -e $dir) then mkdir $dir;echo "repertoire "$dir" cree";fi
cd $dir

#nettoyage
if (test `ls |grep ".pdf" |wc -l` != "0") then
typeset -i i;i=1;while (test -e $i) do;i+=1;done
mkdir $i
mv *.pdf $i
if (test -e index) then mv index $i;fi
if (test -e pdfmerge.tex) then mv pdfmerge.tex $i;fi
fi
if (test -e index) then rm -f index;fi

echo "lx,ly,rx,ry,orientation,cf entete de prog2" >>index
#telechargement des pieces jointes : les messages sont dans le dossier scan_lp10 de la deuxieme collection ; les pieces jointes sont sauvegardees dans ~/scan/
for ((i=1;i<n;i+=1)) do
a=`echo $i |sed 's/./,&/g'`
b=`pwd |sed 's/./,&/g'`
#xterm -geometry 100x6 -e 'pine -c 2 -f scan_lp10 -I"i,j"$a",CR,>,>,s,^k,s,c,a,n,/"$a",.,p,d,f,CR,q"'
#echo "j"$a",CR,>,>,s,^k"$b",/"$a",.,p,d,f,CR,q"
#/usr/bin/pine -c 2 -f "scan_"$1 -I"i,j"$a",CR,>,>,s,^k"$b",/"$a",.,p,d,f,CR,q" >/dev/null
/usr/bin/alpine -c 2 -f "scan_"$1 -I"i,j"$a",CR,>,>,s,^k"$b",/"$a",.,p,d,f,CR,q" >/dev/null
echo $i".pdf" >>index
echo -n $i" "
done
echo
fi
fi
fi

~/scan/prog2
#! /bin/zsh
# usage './prog2 [dir,index,nom_dest]'
# ex :
#'./prog2 ./ index1 McCord
# cf http://zsh.sourceforge.net/Doc/Release/zsh_11.html#SEC38 pour la syntaxe zsh

#concatenation dans pdfmerge.pdf
#lx=0cm;ly=0cm;rx=28.9cm;ry=20.9cm pour un format d'origine A4 landscape
#supprimer les options clip,bb=lx ly rx ry si on veut garder le document entier
#lx=80pt #donnees issues de gv option PixelBased de l'onglet 1.000

#ex d'entete pour le fichier index
#lx,ly,rx,ry,landscape, (format d'origine, landscape)
#lx,ly,rx,ry,portraiti, (format d'origine, portrait)
#0cm,0cm,28.9cm,20.9cm,landscape, (format a4 landscape)
#454,50,830,650,portrait,stop, (format pt issu de gv, portrait, pas de compilation avec pdflatex)

#Plus bas : entier $j comme numero de page (changer le j initial et l'incrementation) ou bien $i comme numero de page


dir=$1;if (test $dir"" = "") then dir=".";fi
if (test ! -d $dir) then echo "repertoire "$dir" inconnu"
else
index=$2;if (test $index"" = "") then index=$dir"/index";fi
if (test ! -e $index) then echo "fichier "$index" inconnu"
else
a=`sed -n '1p' $index`
lx=`echo $a |cut -d"," -f1`
ly=`echo $a |cut -d"," -f2`
rx=`echo $a |cut -d"," -f3`
ry=`echo $a |cut -d"," -f4`
orientation=`echo $a |cut -d"," -f5`
st=`echo $a |cut -d"," -f6`
typeset -i nn;nn=`cat $index|wc -l`-1
if (test $lx"" = "" -o $nn -lt 1) then
echo "fichier index absent ou mal defini"
else
echo $index": "$lx,$ly,$rx,$ry,$orientation,$nn" pages",$st
rm -f $dir/pdfmerge.tex
if (test $orientation = "landscape") then
  width=29.6;height=20.9
  cp $HOME/scan/pdfmerge.landscape $dir/pdfmerge.tex
else
  width=20.9;height=29.6
  cp $HOME/scan/pdfmerge.portrait $dir/pdfmerge.tex
fi

echo "\\\\usepackage[hidelinks]{hyperref}\n\n" >>$dir/pdfmerge.tex
echo "\\\\begin{document}\n\\\\begin{center}\n" >>$dir/pdfmerge.tex

typeset -i j;j=-10
foreach i in `sed '1d' $index`
j=j+2;
echo "\\\\renewcommand{\\\\thepage}{"$j"/220}" >>$dir/pdfmerge.tex
#echo "\\\\renewcommand{\\\\thepage}{"$i"}" >>$dir/pdfmerge.tex
if (test $lx"" = "lx") then
echo "\\\\includegraphics[width="$width"cm,totalheight="$height"cm,keepaspectratio,clip]{"$i"}" >>$dir/pdfmerge.tex
else
echo "\\\\includegraphics[width="$width"cm,totalheight="$height"cm,keepaspectratio,clip,viewport="$lx" "$ly" "$rx" "$ry"]{"$i"}" >>$dir/pdfmerge.tex
fi
echo "\\\\newpage\n" >>$dir/pdfmerge.tex

echo -n `echo $i |cut -d"." -f1`" "
end
echo
echo "\\\\end{center}\n\\\\end{document}\n" >>$dir/pdfmerge.tex
#export dir;xterm -geometry 100x6 -e 'cd $dir;pdflatex pdfmerge'
if (test $st"" != "stop") then
cd $dir;pdflatex -interaction batchmode pdfmerge >/dev/null
name=`echo $3 |cut -d"." -f1`;if (test $name"" = "") then name=pdfmerge;else mv pdfmerge.pdf $name".pdf";fi
echo "fichier "$dir"/"$name".pdf genere"
else echo "fichier "$dir"/pdfmerge.tex genere";fi
fi
fi
fi

~/Desktop/Ens14-15/L1md/Scan-int1/scriptd
#!/bin/zsh
# scan recto-verso type livre format a3 bord 1
# http://zsh.sourceforge.net/Doc/Release/zsh.html
file=$1 #file="20150112141933.pdf"
#arg=$2;posname=${(P)${arg}};print $posname #(1 Hasnaoui 3 BenHamouda)
print $argv ${#argv}
#exit
typeset -i i
for ((i=2;i<${#argv};i+=2)) do
#print $i $file $argv[1+i]
pdfjam $file $argv[i] --trim '21cm 0cm 0cm 0cm' --clip true --outfile 1.pdf
pdfjam $file $argv[i] --trim '0cm 0cm 21cm 0cm' --clip true --outfile 4.pdf
pdfjam $file $((1+$argv[i])) --trim '21cm 0cm 0cm 0cm' --clip true --outfile 3.pdf
pdfjam $file $((1+$argv[i])) --trim '0cm 0cm 21cm 0cm' --clip true --outfile 2.pdf
pdftk [1-4].pdf cat output $argv[1+i]".pdf"
done

~/Desktop/Ens14-15/L1md/Scan-int1/superscript
#!/bin/zsh
setopt extended_glob #pour # dans [!\ ]#.pdf
cat liste |while read -r i;do
print -n $i
if [[ "$i" = [!\ ]#.pdf* ]] then
print " ok"
./scriptd ${(s: :)i}
else
print " bad"
fi
done

~/Desktop/L2MASS-coord-14-15/sem3/Notes-sem3/assemblage/test/script
#! /bin/zsh
# ajout du champ c de chaque ligne de "import" à "base" en position d (champ existant écrasé) par identification du champ id
# la colonne d dans base est supposée déjà exister
exec >> log.txt
b=`sed -n "2p" index.txt`
#base="notes-s3.csv";id=3;del=3
base=`echo $b|cut -d"," -f1`".csv";id=`echo $b|cut -d"," -f2`;del=`echo $b|cut -d"," -f3`
print "\n"$b"\n" >>log.txt
cp $base $base"~"
foreach f in `sed -n "/^x,/p" index.txt` # pb avec les caract. blancs
import=`echo $f|cut -d"," -f2`".csv"
print "\n"$f"\n" >>log.txt
c=`echo $f|cut -d"," -f3`
d=`echo $f|cut -d"," -f4`
idbis=`echo $f|cut -d"," -f5`;if [[ $idbis"" != "" ]] then;id=$idbis;fi
sed -n "1,"$del"p" $base > out
##foreach i in `sed '1d' $base` #traite un caract blanc comme fin de ligne
sed "1,"$del"d" $base |while read -r i;do
#sed -n '2p' $base |while read -r i;do #traite la 2ème ligne uniquement, pour test
no=`echo $i|cut -d"," -f$id` #no etudiant champs 4 du fichier base
if [[ $no"" == "" ]] then
gr=""
print "champ "$id" est vide"
else
gr=`sed -n "/$no/p" $import |cut -d"," -f$c`
fi
##sed -n "/$no/{s/,/,$gr/$((c-1))p}" $base >>$out
gro=`echo $i|cut -d"," -f$d`
if [[ $gro"" != "" ]] then
echo "champ "$d" de la ligne \""$i"\" contient déjà \""$gro"\""
fi
if [[ $gr"" == "" ]] then
echo $i>>out
else
echo $i|sed "s/,[^,]*/,$gr/$((d-1))">>out
fi
echo $no","$gr","$gro
done
mv out $base
end


~/Desktop/L2MASS-coord-14-15/sem3/Notes-sem3/assemblage/test/script3
#! /bin/zsh
# usage ./script3 id base note_inf col_1ère_note ligne_titre > out.csv
# ouvrir $base".csv" avec libreoffice pour déterminer col_1ère_note et ligne_titre
# ./script3 aktas SLZ2A-13-14 0.5 3 2;cat aktas.csv
# ./script3 aktas notes-s3 0 5 2
#exec > log3.txt

id=$1;if [[ $id"" == "" ]] then id="aktas";fi
col=$4;if [[ $col"" == "" ]] then col=5;fi
lt=$5;if [[ $lt"" == "" ]] then lt=1;fi
base=$2;if [[ $base"" == "" ]] then base="notes-s3";lt=2;fi
ninf=$3;if [[ $ninf"" == "" ]] then ninf=-1;fi

print $id,$base,$col,$lt"\n"
#declare -A ix # cf http://zshwiki.org/home/scripting/array
typeset -a titre
typeset -i n;n=0
head=`sed -n $lt"p" $base".csv"`
echo $head |sed -e "s/,/\n/g" |while read -r i;do
n=n+1;titre[n]=$i
#ix[$i]=$n
done
#print ${(k)ix} # cf http://zshwiki.org/home/scripting/array
#print "\n"$ix["web"]
result=`grep -i $id $base".csv"`

#print $head;print $result
echo $head |cut -d"," -f1-$((col-1))
echo $result |cut -d"," -f1-$((col-1))
echo
for ((i=col;i<n+1;i++));do
r=`echo $result | cut -d"," -f$i |sed -e "s/\"//g"`
if [[ $r -ge $ninf ]] then
#echo ${(k)ix[(r)$i]}","$r
echo $titre[$i]","$r
fi
done