I was wondering how to print the contents of a file above the occurrence of a pattern in another file. I know that using
sed -n '/^PATTERN/i\\
INSERTING' filename
would insert above the pattern but can i display the contents of a file instead?
This command got close
sed '/^Stephen/r siid' addrfile
but i want the file to be displayed before the occurrence of the pattern
Asked
Active
Viewed 46 times
1

NOOBCAKE
- 21
1 Answers
0
sed -e '/PATTERN/r file' -e '$!N;P;D'
Doesn't work for PATTERN on the last line.
With GNU sed
:
sed '/PATTERN/e cat file'

Stéphane Chazelas
- 544,893