Bonsoir,
N'étant pas "toujours" satisfait des astuces que je trouve (euphémisme), je fais référence à ce fil pour pousser un peu plus loin la réflexion et voir si il y a mieux que mon résultat.
http://www.developpez.net/forums/d12...happement-sed/
Effectivement c'est bien pratique de pouvoir adapter nos délimiteurs de champs sed dans les substitutions, mais quid de sed -n "/motif/p" ou sed -n '/motif/!d' ... Ben ça marche pas.
'%?,# etc' comme délimiteur, exemple:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 echo -e "/path/to/machin1\n/path/to/machin2\n/path/to/machin3" | sed '#/path/to/machin2#!d' /path/to/machin1 /path/to/machin2 /path/to/machin3 echo -e "/path/to/machin1\n/path/to/machin2\n/path/to/machin3" | sed -n '#/path/to/machin2#p' ... idem ...
Par contre,j'utilise des chaînes mais liste peut très bien être un fichier (à adapter en conséquence). Est-ce qu'il y a une meilleur astuce ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 $ motif="/path/to/machin2" ; liste="/path/to/machin1\n/path/to/machin2\n/path/to/machin3" ; sed -n "/$(sed 's%/%\\\/%g' <<< $motif)/p" < <(echo -e $liste) /path/to/machin2
Partager