Sponsored Content
Top Forums Shell Programming and Scripting searching & replacing/removing only certain HTML tags Post 302415578 by naphelge on Friday 23rd of April 2010 01:23:19 AM
Old 04-23-2010
hey guys things are coming slowly but surely with sed. now I have sed script files that do almost everything I need, actually they do, but still with quite a bit of manual effort.

I am trying to use a sed script inside of a bash for loop to automatically change $name variables, but I am having some problems because the file names overwrite each each iteration of the for loop, and by the end only the last name in the for list gets changed in the filename.

can someone please help me fine tune this so that somehow (with a counter I think, but I have played with counters and cannot get seem to get the desired result) the for loop goes thru and changes the name, saves the result, changes the name to the next one and using the saved file from the previous iteration.

Code:
#!/bin/bash
for name in BAPTISTA TRANIO HORTENSIO GREMIO GRUMIO PETRUCHIO WIDOW
do		
		#append colon after any lines that only contain name
		#put name on new line whenever a period immediately proceeds it
		#put name on new line whenever a closing bracket immediately proceeds it
		#all instances of '”' need to be substitued for '"'
		#rm any chars coming after the colon following the name
	sed -e "/^$name$/s/$name/$name\:/g" -e	"/$name/s/.$name/.\n$name\:/g" -e "/$name/s/)$name/)\n$name\:/g" -e "/$name/s/\"$name/\"\n$name\:/g" -e "s/\($name\:\).*/\1/g" -e "/$name/s/$name\:/<tr><td class=\"padleft6\"><b>$name\:<\/b><\/td><\/tr>/g" $filename1 > $filename2
done

All of the sed subs work fine if I call them using the sed file command. And I am pretty sure they should work here as is, since the end result I have, the name WIDOW gets changed in the file as desired. I think the rest of the names do also, but then get written over.

I know that I still need to manually enter the names into the bash script, but doing that and having the for loop correct will still save me a schwack of time.

Thanks for any help because I have never done any programming before, so lots of new ideas here that are probably in need of modification

cheers,
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

searching through a file and replacing

Hi can anyone show me how to search through a file (multiple columns) and based on say one column if empty and another being popluted and if both senario's are true then get information from another file matching the data from the populated column based upon the populated column and bring through... (2 Replies)
Discussion started by: Gerry405
2 Replies

2. Shell Programming and Scripting

removing html tags via parameter expansion

Hi all- I have a variable that contains a web page: echo $STUFF <html> <head> <title>my page</title></head> <body> blah blah etc.. Can I use the shell's parameter expansion abilities to remove just the tags? I thought that FIXHTML=${STUFF//<*>/} might do it, but it didn't seem to... (2 Replies)
Discussion started by: rev66
2 Replies

3. Shell Programming and Scripting

In PHP replacing text between TAGS & URI information in Title Tag

Hi, what I am trying to do in PHP, is to replace the Title. I need some of the URL information inside aswell depending on the domain. The title is always different so I need to store it in a variable, put the url info like described below in front of it. Here is an example how it should... (0 Replies)
Discussion started by: lowmaster
0 Replies

4. Shell Programming and Scripting

Replacing variable values in html tags

Hi please help me with this . I have a file test.txt with following content $cat test.txt <td>$test</td> <h2>$test2</h2> and I have a ksh with following content $cat test.ksh #!/bin/ksh test=3 test2=4 while read line do echo $line done < test.html I am expecting the output as (4 Replies)
Discussion started by: panduandpavan
4 Replies

5. UNIX for Advanced & Expert Users

Removing HTML tags

Hello Unix Gurus I am having a problem with one of the files that i am generating using a Unix Script. This Unix Scripts connects to the MY SQL Server and loads the data into a Text file. While generating the Text file for one of the tables the value in one of the column is as follows. <p>... (3 Replies)
Discussion started by: chetan.mudike
3 Replies

6. Shell Programming and Scripting

Removing html tags

I store different variance of the below in an xml file. and apparently, xml has an issue loading up data like this because it contains html tags. i would like to preserve this data as it is, but unfortunately, xml says i cant. so i have to strip out all the html tags. the examples i found... (9 Replies)
Discussion started by: SkySmart
9 Replies

7. Shell Programming and Scripting

Removing all except couple of html tags from html file

I tried to find elegant (or at least simple) way to remove all but couple of html tags from html file, but all examples I found dealt with removing all the tags. The logic of the script would be: - if there is <li> or <ul> on the line, do nothing (=write same line to output) - if there is:... (0 Replies)
Discussion started by: juubuntu
0 Replies

8. UNIX for Advanced & Expert Users

Mutt for html body and multiple html & pdf attachments

Hi all: Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project. There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues. Running with... (1 Reply)
Discussion started by: raggmopp
1 Replies

9. Homework & Coursework Questions

Script: Removing HTML tags and duplicate lines

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: You will write a script that will remove all HTML tags from an HTML document and remove any consecutive... (3 Replies)
Discussion started by: tburns517
3 Replies

10. UNIX for Dummies Questions & Answers

Replacing HTML tags with sed

Ok, so this is stupid simple, and I know I am going to feel like an idiot when I get help. I am altering a HTML report that has contraband in it so that the links to said contraband and the images are not shown. The link/img pairs are in the form of : <a... (5 Replies)
Discussion started by: twjolson
5 Replies
MRTG(1) 							       mrtg								   MRTG(1)

NAME
mrtg - What is MRTG SYNOPSIS
The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing GIF images which provide a LIVE visual representation of this traffic. Check http://www.stat.ee.ethz.ch/mrtg/ to see what it does. Go to http://people.ee.ethz.ch/~oetiker/webtools/mrtg for all the details about mrtg. USER PAGES
MRTG is written in Perl and C and works under UNIX and Windows NT. MRTG is being successfully used on many sites around the net. Check the MRTG-Site-Map on: http://people.ee.ethz.ch/~oetiker/webtools/mrtg/users.html HIGHLIGHTS
Portable MRTG works on most UNIX platforms and Windows NT. Perl MRTG is written in perl and comes with full source. Portable SNMP MRTG Uses a highly portable SNMP implementation written entirely in Perl thanks to Simon Leinen. There is no need to install any exter- nal SNMP package. SNMPv2c support MRTG can read the new SNMPv2c 64bit counters. No more counter wrapping. Reliable Interface Identification Router interfaces can be identified by IP address, Description and Ethernet address in addition to the normal Interface number. Constant size Logfiles MRTG's logfiles do NOT grow. Thanks to the use of a unique data consolidation algorithm. Automatic Configuration MRTG comes with a set configuration tools which make configuration and setup very simple. Performance Time critical routines are written in C thanks to the initiative of Dave Rand my Co-Author. GIF free Graphics Graphics are generated directly in PNG format, using the GD library by Thomas Boutell. Customizability The look of the webpages produced by MRTG is highly configurable. RRDtool MRTG has built in hooks for using RRDtool. If you are straped for performance this may help. DETAILS
MRTG consists of a Perl script which uses SNMP to read the traffic counters of your routers and a fast C program which logs the traffic data and creates beautiful graphs representing the traffic on the monitored network connection. These graphs are embedded into webpages which can be viewed from any modern Web-browser. In addition to a detailed daily view, MRTG also creates visual representations of the traffic seen during the last seven days, the last four weeks and the last twelve months. This is possible because MRTG keeps a log of all the data it has pulled from the router. This log is automatically consolidated, so that it does not grow over time, but still contains all the relevant data for all the traffic seen over the last two years. This is all performed in an efficient manner. Therefore you can monitor 200 or more network links from any halfway decent UNIX box. MRTG is not limited to monitoring traffic though, it is possible to monitor any SNMP variable you choose. You can even use an external pro- gram to gather the data which should be monitored via MRTG. People are using MRTG, to monitor things such as System Load, Login Sessions, Modem availability and more. MRTG even allows you to accumulate two or more data sources into a single graph. HISTORY
In 1994 I was working at a site where we had one 64kbit line to the outside world. Obviously everybody was interested in knowing how the link was performing. So I wrote a quick hack which created a constantly updated graph on the web, showing the traffic load on our Internet link. This eventually evolved into a rather configurable Perl script called MRTG-1.0 which I released in spring 1995. After a few updates I left my job at DMU, to start work at the Swiss Federal Institute of Technology. Due to lack of time I had to put MRTG aside. One day in January of 1996, I received email from Dave Rand asking if I had any ideas why MRTG was so slow. Actually I did. MRTG's programming was not very efficient and it was written entirely in Perl. After a week or so, Dave wrote back to me and said he had tried what I had suggested for improving MRTG's speed. Since the changes did not help much, he had decided to rewrite the time-critical sections of MRTG in C. The code was attached to his email. His tool increased the speed of MRTG by a factor of 40! This got me out of my 'MRTG ignorance' and I started to spend my spare time developing of MRTG-2. Soon after MRTG-2 development had begun I started to give beta copies to interested parties. In return I got many feature patches, a lot of user feedback and bug fixes. The product you are getting now is wouldnt be in this state if it hadn't been for the great contributions and suport I received from of many people. I would like to take this opportunity to thank them all. (See the files CHANGES for a long list of folk people who helped to make MRTG what it is today) READ ON
Learn more about MRTG by going to the mrtg home page on: http://people.ee.ethz.ch/~oetiker/webtools/mrtg AUTHOR
Tobias Oetiker <oetiker@ee.ethz.ch> and many contributors 3rd Berkeley Distribution 2.9.17 MRTG(1)
All times are GMT -4. The time now is 11:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy