Retirer les lignes vides d’un fichier sous Linux
Ces petites commandes méritent à être retenues, pour gagner du temps le jour où on est confronté au problème… et que l’on a pas Google sous la main !
Prenons un fichier test.txt qui nous servira d’exemple :
[root@pc-linux]# cat test.txt test 1 test 2 test 3 test 4 test 5 test 6 test 7
Avec sed :
[root@pc-linux]# sed '/^$/D' test.txt test 1 test 2 test 3 test 4 test 5 test 6 test 7
Avec awk :
[root@pc-linux]# awk NF test.txt test 1 test 2 test 3 test 4 test 5 test 6 test 7
Variante :
[root@pc-linux]# awk '/./' test.txt test 1 test 2 test 3 test 4 test 5 test 6 test 7
Sans awk ni sed :
[root@pc-linux]# cat test.txt | grep '.' test 1 test 2 test 3 test 4 test 5 test 6 test 7
Variante :
[root@pc-linux]# cat test.txt | grep -v '^$' test 1 test 2 test 3 test 4 test 5 test 6 test 7
Publié le
13 juin 2010 | Catégorie(s) :
Linux |
Aucun commentaire
