J’ai le fichier suivant:
first second third fourth third fifth sixth
Utiliser un cat file | sed -n '/third/,$p'
cat file | sed -n '/third/,$p'
Je peux imprimer à partir du premier match, pour obtenir:
third fourth third fifth sixth
Est-il possible de modifier la commande sed
telle sorte qu’elle ignore essentiellement la première correspondance et imprime la deuxième partie? Ce serait:
third fifth sixth
Avec sed:
sed '1,/third/d' file | sed -n '/third/,$p'
Sortie:
troisième cinquième sixième
Voici un awk
qui fait cela en gardant un tampon pour stocker toutes les lignes de l’occurrence du third
dans une ligne et en réinitialisant le tampon quand le third
sera retrouvé:
awk '/third/{p=$0 RS; next} p{p=p $0 RS} END{printf "%s", p}' file
third fifth sixth
Alternativement, vous pouvez utiliser ce tac + awk
:
tac file | awk '1; /third/{exit}' | tac
third fifth sixth
Avec gnu sed
sed '/third/!d;:A;N;/\nthird/!{s/[^\n]*\n//;bA };s/[^\n]*\n//;:B;N;bB' infile