I want to insert some text in the middle of a file. The text to insert would be after a specific line, say, "<begin>
". I don't know the line number, nor do I know the number of lines in the text to insert. I only know that after the line that reads "<begin>
" I need to insert the content of another file.
I just don't know how to use awk to do something like this.
Thanks 🙂
Best Answer
Create a file with the following code. You could save it as:
insertfile.awk (or whatever you wish)
The awk command line parameters used are:
Then, to use it you call awk like this:
In the awk script, you can edit it like this:
If you want to "pipe" the input data into the script instead of getting it from a file, edit the insertfile.awk script like this:
Then, to use it you call awk like this: