J'ai un fichier dans un format :
==============================
nfsserver1.example.com
==============================
/vol/vol1 -sec=sys,rw=clinet1,root=clinet10
/vol/vol2 -sec=sys,rw=clinet1,root=clinet10
==============================
nfsserver3.example.com
==============================
==============================
nfsserver4.example.com
==============================
/vol/vol1 -sec=sys,rw=clinet4,root=clinet10
et j'ai besoin de le reformater en ceci :
nfsserver1.example.com /vol/vol1 -sec=sys,rw=clinet1,root=clinet10
nfsserver1.example.com /vol/vol2 -sec=sys,rw=clinet1,root=clinet10
nfsserver3.example.com
nfsserver4.example.com /vol/vol1 -sec=sys,rw=clinet4,root=clinet10
C'est ce que j'ai essayé :
while read server; do
echo "---- ${server} -----------------------------------------"
cat file.txt|\
grep -v "========"|\
awk -v srv=${server} '/^nfsserver1\.example\.com$/ {f=1} f; /^$/ {f=0}'|\
grep -v "^$"|\
awk -v srv=${server} '{printf("%s %s\n",srv,$0)}'
echo
server=""
done < <(cat file.txt|grep "^[a-z].*\.example\.com$")
mais je ne sais pas exactement comment je peux intégrer une variable dans une recherche de motifs. J'ai essayé ceci :
awk -v srv=${server} '$0 ~ srv {f=1} f; /^$/ {f=0}'
Mais cela produit une sortie incorrecte et je voudrais avoir une correspondance exacte avec la variable.
---- nfsserver1.example.com -----------------------------------------
nfsserver1.example.com nfsserver1.example.com
nfsserver1.example.com /vol/vol1 -sec=sys,rw=clinet1,root=clinet10
nfsserver1.example.com /vol/vol2 -sec=sys,rw=clinet1,root=clinet10
nfsserver1.example.com nfsserver1.example.com /vol/vol1 -sec=sys,rw=clinet1,root=clinet10
nfsserver1.example.com nfsserver1.example.com /vol/vol2 -sec=sys,rw=clinet1,root=clinet10
nfsserver1.example.com nfsserver3.example.com
nfsserver1.example.com nfsserver4.example.com /vol/vol1 -sec=sys,rw=clinet4,root=clinet10
---- nfsserver3.example.com -----------------------------------------
nfsserver3.example.com nfsserver3.example.com
nfsserver3.example.com nfsserver3.example.com
nfsserver3.example.com nfsserver4.example.com /vol/vol1 -sec=sys,rw=clinet4,root=clinet10
---- nfsserver4.example.com -----------------------------------------
nfsserver4.example.com nfsserver4.example.com
nfsserver4.example.com /vol/vol1 -sec=sys,rw=clinet4,root=clinet10
nfsserver4.example.com nfsserver4.example.com /vol/vol1 -sec=sys,rw=clinet4,root=clinet10
---- nfsserver3.example.com -----------------------------------------
nfsserver3.example.com nfsserver3.example.com
nfsserver3.example.com nfsserver3.example.com
nfsserver3.example.com nfsserver4.example.com /vol/vol1 -sec=sys,rw=clinet4,root=clinet10
Beaucoup de lignes dont je n'ai pas besoin. Je ne sais pas vraiment d'où elles viennent.