Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern matching question

Status
Not open for further replies.

teser

Technical User
Mar 6, 2001
194
US
How would I write something in Unix/AWK or Perl to change sentences or
paragraphs in many web page documents. All the documents have
some similiar sentences and paragraphs. On occasion I need to change or
delete a specific sentence or paragraph. Any suggestions?
 

You could use sed for your paragraph changes:
sed ' 10,30 s/bogus/foo/' filename >temp &&
mv temp filename
(lines 10 through 30, sub bogus for foo)
This is very basic, sed has the ability to branch to labels in text and do some fairly detailed work, and it is easy to script.

For running through problem files sentence
by sentence.

for x in `ls *.html`
do
if [ -f "$x" ]#better safe ...
then
awk '
function change_it( orig, rep, n) {
print $0
printf "String to change: "
getline orig < &quot;-&quot;
printf &quot;Replacement: '
getline rep < &quot;-&quot;
if (rep && orig) {
n = gsub(orig, rep, $0)
return $n
}
}
{
change_it()
print $n > FILENAME
}' $x
fi
done

That interactively goes through, line by line. Will take forever with large files,
or you could truncate them before you go.

Bye.
 
Hi There,
Could someone help in modifying certain words in a file?
For example, I want to modify the word Variable enclosed in <TAG>Variable<\TAG> and replace it with 100. I know that awk has this pattern matching capability but I am not familiar with it. Kindly advice if you have any ideas. Thanks...
-GTFY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top