From 6e4f21d24163dfa5b401d408f4bf4f3c20f743d3 Mon Sep 17 00:00:00 2001 From: Alexis Ben Miloud--Josselin Date: Mon, 6 Feb 2023 10:33:57 +0100 Subject: [PATCH] =?UTF-8?q?TipsShell:=20ajouter=20m=C3=A9thodes=20pour=20r?= =?UTF-8?q?ang=20d=E2=80=99un=20=C3=A9l=C3=A9ment=20dans=20une=20liste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TipsShell.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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}