![]() |
|
Perl Monk, Perl Meditation | |
PerlMonks |
Re: How to insert the content of a file into another file before/after a pattern match?by shmem (Chancellor) |
on May 09, 2015 at 18:41 UTC ( [id://1126202]=note: print w/replies, xml ) | Need Help?? |
In File1 I see a pattern: the component blocks, architecture and signal declarations are separated by an empty line. Thus, the file is organized into paragraphs. There is a command line switch for reading files in paragraph mode: -00 (see perlrun). The -n and -p switches construct an implicit loop around your code which does the read for you. So, one way to achieve your goal (remember TIMTOWTDI - There Is More Than One Way To D It) would be something along the following:
Code is untested. Note that the second file containing the snippet comes first on the command line.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|