I'm trying to use sed/awk to copy a range of text from the beginning of file1 to a specific line. Then add that output to the beginning of file 2 for a script I'm writing.
The following command does what I want to extract from line 1 to the line that I want to end at in file1.
awk '1;/### BEGIN ###/{exit}' file1
However, I don't know how to get this content to be copied to the beginning of file2 which already has text in it. I experimented with sed below to add a new line to beginning of file2 which works.
sed -e '1i\A new line is added to top of document' > file2
How do I use the output of awk to sed to update file2? Is there a better way?
edit: I've been experimenting and this command works below. However, I'm still up to learn if there is other ways to do this that might be better or more efficent.
cat <(awk '1;/### BEGIN ###/{exit}' file1) file2 > file3
Sample text file1:
Line1
Line...
### BEGIN ###
additional text not wanted...
Sample text file2:
<insert text from file 1 above existing text>
Existing text...
awk ... | cat - file1 > file2
. The dash stands for standard input. The result is in file2; if needed, you can rename it file1.