diff --git a/TipsShell.md b/TipsShell.md index e7dc982c..34a365a5 100644 --- a/TipsShell.md +++ b/TipsShell.md @@ -125,13 +125,27 @@ $ exit ## Connaître le rang d'un élément dans une liste -Utilisation de **tac** pour inverser la liste, sans la trier : +Avec `grep` : -~~~{.bash} -$ ./liste_serveur.sh | tac | grep -n NOUVEAU_SERVEUR +~~~ +$ ./liste_serveur.sh | grep -n NOUVEAU_SERVEUR 2:NOUVEAU_SERVEUR ~~~ +Avec `nl` : + +~~~ +$ ./liste_serveur.sh | nl | grep NOUVEAU_SERVEUR + 2 NOUVEAU_SERVEUR +~~~ + +Avec `awk` : + +~~~ +$ ./liste_serveur.sh | awk '/NOUVEAU_SERVEUR/ { printf "%u\t%s\n", NR, $0 }' +2 NOUVEAU_SERVEUR +~~~ + ## Ajout mot en début de chaque ligne d'un buffer ~~~{.bash}