Je vais soumettre le formulaire en utilisant cURL, où une partie du contenu provient d'un autre fichier, sélectionné en utilisant sed
Si param1
est le modèle de correspondance de ligne d'un autre fichier utilisant sed
, la commande ci-dessous fonctionnera correctement :
curl -d param1="$(sed -n '/matchpattern/p' file.txt)" -d param2=value2 http://example.com/submit
Passons maintenant au problème. Je veux afficher uniquement le texte entre 2 motifs correspondants, à l'exclusion du motif correspondant lui-même.
Disons file.txt
contient :
Bla bla bla
firstmatch
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.
secondmatch
The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
Actuellement, beaucoup de "beetween 2 matching pattern" sed
la commande ne supprimera pas firstmatch
et secondmatch
.
Je veux que le résultat devienne :
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.
Réponse acceptée :
Voici une façon de procéder :
sed '1,/firstmatch/d;/secondmatch/,$d'
Explication :de la première ligne à la ligne correspondant à firstmatch , effacer. À partir de la ligne correspondant à secondmatch à la dernière ligne, supprimer.