Sed
Exemples de sed
- Bonne petite Doc
- Bonne synthèse avec examples
- Good examples SED
- SED on line
- Fusion de lignes
- Si dans ligne on a le caractère ou mot donné ici SSH
Exemple :
user@user:~/$ ls -1 Utilitaires_* Utilitaires_AWK.txt Utilitaires_SED.txt Utilitaires_SSH.txt Utilitaires_Vi.txt ogallego@ogallego:~/$ ls -1 Utilitaires_* |sed -e "/SSH/N;s/\n/ /;" Utilitaires_AWK.txt Utilitaires_SED.txt Utilitaires_SSH.txt Utilitaires_Vi.txt
- Simple fusion de lignes avec retrait LF ou CRLF de la 1ere ligne
Exemple :
user@user:~/$ ls -1 Utilitaires_* Utilitaires_AWK.txt Utilitaires_SED.txt Utilitaires_SSH.txt Utilitaires_Vi.txt user@user:~/$ ls -1 Utilitaires_* | sed '$!N;s/\n/ /' Utilitaires_AWK.txt Utilitaires_SED.txt Utilitaires_SSH.txt Utilitaires_Vi.txt
- Supprimer des lignes :
**********Contenu fichier user@user:~/$ ls -1 Utilitaires_* Utilitaires_AWK.txt Utilitaires_SED.txt Utilitaires_SSH.txt Utilitaires_Vi.txt **********Supprimer 1 et 2 lignes du fichier user@user:~/$ ls -1 Utilitaires_* | sed '1,2d' Utilitaires_SSH.txt Utilitaires_Vi.txt **********Supprimer de la 2 à la 3 ligne du fichier user@user:~/$ ls -1 Utilitaires_* | sed '2,3d' Utilitaires_AWK.txt Utilitaires_Vi.txt **********Supprimer chaque 2eme ligne du fichier user@user:~/$ cat Utilitaires_* | sed 'n;d' Utilitaires_AWK.txt Utilitaires_SSH.txt *********Supprimer les lignes si en position 7 on trouve ED et/ou en position 12 on trouve ZN user@user:~/$ sed -e '/^.\{7\}ED/d' -e '/^.\{12\}ZN/d' Fic *********les 104 premiers caractères user@user:~/$ sed -r 's/^(.{104}).*/\1/' temp_$$ *********Suppression 5 premieres lignes et recupere les 104 premiers caractères de la ligne user@user:~/$ uxlst lacan ctl status=A since=20171017,0000 full | sed -r 's/^(.{104}).*/\1/;1,5d'
cat $fichier | egrep 'code_edition=|APPLICATION=| CPU Time' | sed '1,$s/^+ //' | sed '$!N;s/\n/ /'| sed '$!N;s/\n/ /' sed -e '/toto/' -> executer commande entre slash sed -n -e '/toto/' fic => que les lignes contenants toto sed -n -e '/toto/=' fic => que les n° de lignes contenants toto Pattern Space ( memoire tampon )
xxgon@hermes:/home/xxgon> more toto C1_AFP9 ;AFAFPR0D C1_ARP0 ;ARPAPR0D C1_BAP0 ;BAIAPR0D C1_CGP9 ;CGERPR0D C1_ERP9 ;ERERPR0D C1_FCP0 ;FCF2PR0D C1_FNP0 ;FNFNPR0D C1_FNP9 ;ERFNPR0D C1_FOP0 ;FOERPR0D C1_GIP0 ;GIGIPR0D C1_OSP0 ;OSOSPR0D C1_MIP9 ;MIMIPR0D C1_ALP0 ;AXGTPR0D C1_ISPD ;ISIEPR0D C1_FNP9 ;ERFNPR0D xxgon@hermes:/home/xxgon> sed 'N;s/\n/ /' toto C1_AFP9 ;AFAFPR0D C1_ARP0 ;ARPAPR0D C1_BAP0 ;BAIAPR0D C1_CGP9 ;CGERPR0D C1_ERP9 ;ERERPR0D C1_FCP0 ;FCF2PR0D C1_FNP0 ;FNFNPR0D C1_FNP9 ;ERFNPR0D C1_FOP0 ;FOERPR0D C1_GIP0 ;GIGIPR0D C1_OSP0 ;OSOSPR0D C1_MIP9 ;MIMIPR0D C1_ALP0 ;AXGTPR0D C1_ISPD ;ISIEPR0D xxgon@hermes:/home/xxgon> sed '$!N;s/\n/ /' toto C1_AFP9 ;AFAFPR0D C1_ARP0 ;ARPAPR0D C1_BAP0 ;BAIAPR0D C1_CGP9 ;CGERPR0D C1_ERP9 ;ERERPR0D C1_FCP0 ;FCF2PR0D C1_FNP0 ;FNFNPR0D C1_FNP9 ;ERFNPR0D C1_FOP0 ;FOERPR0D C1_GIP0 ;GIGIPR0D C1_OSP0 ;OSOSPR0D C1_MIP9 ;MIMIPR0D C1_ALP0 ;AXGTPR0D C1_ISPD ;ISIEPR0D C1_FNP9 ;ERFNPR0D xxgon@hermes:/home/xxgon> sed -ne '/FOP/p' toto C1_FOP0 ;FOERPR0Dsed -e 's/.\(ebu.\)//p' tutu export PS1="C:\$( pwd \| sed 's#/#\\\\\\#g' )\\> "
ls -1 *.html|xargs -I{} echo sed s/utf-8/ISO-8859-15/ {} \> {}_n\;test \$? -eq 0 \&\& mv -v {}_n {}|sh sed s/utf-8/ISO-8859-15/ img0.html > img0.html_n;test $? -eq 0 && mv -v img0.html_n img0.html sed s/utf-8/ISO-8859-15/ img1.html > img1.html_n;test $? -eq 0 && mv -v img1.html_n img1.html sed s/utf-8/ISO-8859-15/ img2.html > img2.html_n;test $? -eq 0 && mv -v img2.html_n img2.html sed s/utf-8/ISO-8859-15/ img3.html > img3.html_n;test $? -eq 0 && mv -v img3.html_n img3.html sed s/utf-8/ISO-8859-15/ Schema_CFT_EAI_Helios.html > Schema_CFT_EAI_Helios.html_n;test $? -eq 0 && mv -v Schema_CFT_EAI_Helios.html_n Schema_CFT_EAI_Helios.html « img0.html_n » -> « img0.html » « img1.html_n » -> « img1.html » « img2.html_n » -> « img2.html » « img3.html_n » -> « img3.html » « Schema_CFT_EAI_Helios.html_n » -> « Schema_CFT_EAI_Helios.html »
**********Numeroter les lignes d'un fichier sed = fichier | sed 'N; s/\n/: /' **********Supprimer chaque 2eme ligne du fichier sed 'n;d' fichier
Previous page: AWK_Doc
Page suivante : Editeur Vi