Insert the content of a file (with command r?)
Laurent Le Brun <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <CA+j=sHCFigYHgqyiT1BGV=dL7vKZqV3f=j3rs2fo9reGvusxUg@mail.gmail.com> |
Hi, I'd like to insert the content of a file when the input matches some regexp. It tried this simple script: /regexp/r file.txt It works fine, except that it's inserting the content of the file after the line matching the regexp. I'd like to insert it BEFORE instead. -- input: 1 2 insert here 3 4 -- file.txt: hello -- script: /here/r file.txt -- output: 1 2 insert here hello 3 4 -- desired output: 1 2 hello insert here 3 4 By playing with the hold space, I managed to make it work for the example, but it fails when the regexp in the first or the last line of the file. Any suggestion? My current workaround is to use the "i" command, but it's not as convenient. I don't really like the way "r" works, it seems like it would be much more useful if it used the pattern space like most commands. -- Laurent