A shell program that replaces a section of a line near a keyword in a text file:
#!/bin/bash file=$1 findpattern=$2 linegap=$3 replacepattern=$4 substitue=$5 Help () {echo Help:echo \$1:file\ ' s full Path \ (include filename\) echo \$2:the key string to is find echo \$3:the line count between the line where key Strin
G in and the line to is modified echo \$4:the string to be replace echo \$5:the string would take place the key string Echoinput () {echo \$1= $file echo \$2= $findpattern echo \$3= $linegap echo \$4= $replacepattern echo \$5= $substi
Tue} If ["$" = ""];then help;
exit-1;
Fi echoinput;
if [!-F ${file}];then echo $file is not exist.
Fi #echo "awk '/${findpattern}/{print NR} ' ${file}";
n= ' awk '/' ${findpattern} ' '/{print NR} ' ${file} ';
If ["$n" = = ""];then Echo can not find ${findpattern} in ${file};
exit-1;
fi echo Find key string $n;
if [!-n $n];then Echo find too much lines.
exit-1;
Fi n2= ' expr $n + ${linegap} ';
Echo would modify line $n 2,line contnet is:;
awk ' nr== ' ${n2} ' {print $} ' ${file}; #echo "sed ${n2} ' s/${replacepattern}/${substitue}/g ' ${file} > tmp${file};" sed ${n2} ' s/' ${replacepattern} ' '/' ${
Substitue} "'/g ' ${file} > Tmp${file}; Diff ${file} Tmp${file}
There are also bugs: You can only run in the current directory of the text file. Not modified.