[plug] Insert one file into another

Ben New ben at leftclick.com.au
Mon Dec 8 16:34:12 WST 2003


Derek,

cat file1 | sed -e '/>>>>.*/ r file2' | sed -e '/>>>>.*/ d'

I'm sure the above can be achieved in only one call to sed...  But the 
above should work anyway, even if it's not particularly efficient.  
(That is, assuming the marker line does start with '>>>>' and the files 
are called 'file1' and 'file2').

In case you were wondering, the first call inserts the (entire) contents 
of file2 after the marker line, the second call removes the marker line.

Regards,
Ben


Derek Fountain wrote:

>I have two text files, and I want to insert one into the other via a shell 
>script. That is, one file has a "marker" line containing something like 
>">>>>", and I want to delete that line and replace it with the contents of 
>the second file.
>
>I'd normally do that from Perl - easy! - but in this case I need to do it from 
>very portable shell script. It's on Linux, so that means bash.
>
>Shell scripting isn't my thing. Can someone tell me how to do this?
>
>  
>

-- 
Ben New
ben at leftclick.com.au


Leftclick Software Development
http://www.leftclick.com.au/






More information about the plug mailing list