Une page dans votre Wiki a été ajoutée ou modifiée. Voici les
détails :
Date : 2006/10/27 11:26
Navigateur : Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.0.7) Gecko/20060921 Ubuntu/dapper-security Firefox/1.5.0.7
Adresse IP : 81.57.110.136
Nom d'hôte : mon75-2-81-57-110-136.fbx.proxad.net
Ancienne révision : http://cli.asyd.net/home/filtres/sed?rev=1161856696
Nouvelle révision : http://cli.asyd.net/home/filtres/sed
Résumé : Ajout de la liste des commandes
Utilisateur : danielcaillibaud
@@ -8,6 +8,78 @@
^ Suprimer les lignes 10,14, et 16 à 20 d'un fichier | sed '10d;14d;16,20d;' <fichier> > |
^ Supprimer les lignes commençant par ; | sed '/%%^%%;/d' <fichier> > |
^ Afficher uniquement les lignes 10 à 15 d'un fichier | sed -n '10,15p' <fichier> > |
^ Afficher uniquement les lignes paires | sed '1~2d' < <fichier> |
+
+ ===== généralités =====
+ * sed -e expression : applique l'expression au flux d'entrée
+ * sed -ne expression : idem, mais n'affiche rien en sortie, sauf si on le précise avec p
+ * sed -i suf -e expression fichier : applique l'expression au fichier (pas besoin de préciser entrée sortie) avec backup de l'ancienne version du fichier en fichier.suf (mettre une chaîne vide à la place de suf pour ne pas avoir de backup)
+
+ expression est en général de la forme
+ * n commande : applique la commande à la ligne n
+ * n,m commande : : applique la commande aux lignes de n à m
+ * /pattern/ commande : applique la commande aux lignes qui vérifient le pattern
+ * /pattern/,/pattern2/ commande : applique la commande aux lignes qui se trouvent entre une ligne qui vérifie pattern et une autre qui vérifie pattern2
+
+ ===== Commandes =====
+ * = : affiche le n° de la ligne
+ * a : ajoute des lignes, par exemple :
+
+ sed -e '/pattern/a\
+ ajout d'une ligne\
+ et d'une autre.' < fichier_src > fichier_dest
+
+ * c : change des lignes complètes, ex (vire le corps des fonctions, blocs compris entre accolades ouvrantes/fermantes qui débutent une ligne et remplace par "[... corps de la fonction ...]"
+
+ sed -e '/^{/,/^}/c\
+ [... corps de la fonction ...]' < fichier.c > resume
+
+ * d : efface la ligne (rmq, "!d" est souvent utilisé pour sélectionner des lignes à garder) et retourne au début du script ou de l'expression avec la ligne suivante du fichier d'entrée.
+ * i : insère avant la ligne.
+ * l : idem p avec les caractères de contrôle
+ * n : passe à la ligne suivante (sans appliquer les commandes suivantes à la ligne courante) et y applique la commande suivante.
+ * s/motif/remplacement/opt
+ * p : affiche la ligne
+ * y/car_src/car_dest/ : substitue des caractères par d'autres
+ * N : ajoute la ligne au patternspace
+
+ ==== cas du rechercher/remplacer ====
+
+ s/search/replace/opt où opt peut être
+ * rien : la 1re occurence est remplacée
+ * g : toutes les occurences sont remplacées
+ * N : seule la Nième occurence est remplacée
+ * p : affiche la ligne si subtitution
+ * w fichier : envoie le résultat de la substitution dans un fichier
+ * I : insensible à la casse (extension GNU)
+
+ Caractères particulier pour le remplacement :
+ * \i ième référence arrière
+ * & chaine complète qui correspond au pattern
+
+ ===== Pour aller plus loin =====
+ Dès que la liste des commandes excède 2 ou 3 instructions, il est plus simple de faire un script à part. Ex:
+ * plutôt que ''sed -e 'exp1; exp2;exp3;exp4;' http://okki666.free.fr/docmaster/articles/linux130.html
~~DISCUSSION~~
--
Ce message a été généré par DokuWiki
http://cli.asyd.net/home/