Hi,
As always there are probably others ways of doing this, but this should work:
- A sed solution -
Code:
#!/bin/bash
sed -i '/header/ {
r newheader
d
}' $1
Sed searches for header (the /header/ part) and if found replace it with the content of the file called newheader (the r newheader and d part). The -i saves changes immediately.
Files used and testrun:
Quote:
cat mainfile
a one line header
Text text .......
Text text .......
Text text .......
Text text .......
cat newheader
This is
--- The New Header ---
that's all folks
./replaceheader mainfile
This is
--- The New Header ---
that's all folks
Text text .......
Text text .......
Text text .......
Text text .......
|