[sed] Append a line after a match

Created on November 30, 2026

The a command adds a line after each line that matches the address. In this example, /apple/ selects the line and the text after a\ supplies the line to insert.

printf 'apple\nbanana\n' | sed '/apple/a\
orange'

Output

apple
orange
banana
Bash Shell command sed