This question and its answers show the content of an existing file ("processedFile") can be inserted into another existing file ("receivingFile") before one of its patterns inside, such that:
sed -i -e '/pattern/r processedFile' receivingFile
At times, such content might result from a previous command-unit, and is not yet written.
At that point, is it possible to insert the outcome of the command-unit into receivingFile without creating/writing processedFile?
Example:
Say, we preprocessed someFile
as follows (reading its content starting from the 4th line to the end of file):
awk 'NR>3' someFile
Now, without writing this to a new file, we want to directly insert it into receivingFile before a pattern such that:
awk 'NR>3' someFile | <insertion commands>
PS: Preferably by using awk
or sed
.
Based on the request from @RomanPerekhrest,
someFile:
# random output
# random
11
0 0 0 23.259058 2.1756592 -1.2097659 -0.074128056 0.34343502 -0.017659865
0 0 0.05 51.091269 4.8520157 -0.0011590485 0.00096592555 0.0059719715 -0.050598505
Preprocessing:
awk 'NR>3' someFile
:
0 0 0 23.259058 2.1756592 -1.2097659 -0.074128056 0.34343502 -0.017659865
0 0 0.05 51.091269 4.8520157 -0.0011590485 0.00096592555 0.0059719715 -0.050598505
receivingFile :
stackExchange is the best.
pattern
Unix stackExchange is the best of the bests.
cat someFile | awk 'NR>3' | <insertion commands>
– Stan Strum Feb 12 '18 at 18:10