Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Simple SED Lesson Presented by Dave Mawdsley, DACS Member, Linux SIG Member February 15, 2012 (modifying HTML tags in an html file)

Similar presentations


Presentation on theme: "A Simple SED Lesson Presented by Dave Mawdsley, DACS Member, Linux SIG Member February 15, 2012 (modifying HTML tags in an html file)"— Presentation transcript:

1 A Simple SED Lesson Presented by Dave Mawdsley, DACS Member, Linux SIG Member February 15, 2012 (modifying HTML tags in an html file)

2 Introduction Sed (Stream Editor) is one of those little commands used in the Bash shell that can do amazing things. Whole books are written about sed. In this example, simple HTML tags in the code for a webpage are converted from upper case to lower case to keep them more in line with current practices. In this lesson, a small Bash script is shown that when made to execute, will make the conversions necessary throughout the entire page. First a look at the HTML text page...

3 The HTML File: simple.html Note that the HTML tags are all in capital letters—not the current practice.

4 A First Look at Sed 1 Here's the type of sed command I'm using: sed -i 's / / / ' filename For example, replace all instances of the word 'dog' with the word 'cat' in the file 'simple.html' so use: sed -i 's/dog/cat/' simple.html The switch -i allows for editing a file in-place. s/ calls for substitution followed by a delimiter. In my example, I'll replace with in 'simple.html' as follows: sed -i 's/ / /' simple.html

5 A Sed Wrinkle—But Overcome 1 Things get a bit messy if a space occurs in either string. Use a backslash just before it if you replace 'bad dog' with 'cat' as follows: sed -i 's/bad\ dog/cat/g' simple.html On the page that follows you'll see how becomes : sed -i 's/ / ' simple.html as otherwise there would be trouble with the '/' inside ' ' that is normally is used as a delimiter for sed.

6 The Bash Script to Convert the Tags

7 The Resulting HTML Page 1

8 Using the Replace Feature of Gedit If simple.html were to be opened in the application gedit, I could use the Search > Replace feature to replace say with everywhere in the document, but then I'd have to do that with every other tag. This could get very tedious and I most probably would miss some of the tags. My Bash script in my home directory takes care of the entire conversion in about one second. The script must be run while in the same folder as simple.html work properly. I simply navigate to the folder containing simple.html and issue the command./uc-lc-convert which converts all the tags at once. My computer knows the path back to uc-lc- convert. To use the code with another file, just change the variable assignment for myfile to the new filename.

9 This OpenOffice.org Presentation 'seduc-lc.odp' can be downloaded from http://madmod.com/freebies.html (modifying HTML tags in an html file) A Simple SED Lesson


Download ppt "A Simple SED Lesson Presented by Dave Mawdsley, DACS Member, Linux SIG Member February 15, 2012 (modifying HTML tags in an html file)"

Similar presentations


Ads by Google