The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to supplement HTML tags with SED DocBrewer Shell Programming and Scripting 3 04-25-2008 09:40 AM
html tags dunryc Shell Programming and Scripting 3 11-29-2007 06:14 PM
How to remove only html tags inside a file? btech_raju Linux 2 11-23-2007 12:25 PM
Automated replacement of HTML Tags nem_kirk SUN Solaris 1 11-17-2005 01:24 AM
unsing sed to strip html tags - help zap Shell Programming and Scripting 3 04-18-2004 04:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 05-22-2008
dejavu88 dejavu88 is offline
Registered User
  
 

Join Date: May 2008
Posts: 18
Remove html tags with bash

Hello,

is there a way to go through a file and remove certain html tags with bash? If it needs sed or awk, that'll do too.

The reason why I want this is, because I have a monitor script which generates a logfile in HTML and every time it generates a logfile, the tags are reproduced. The tags I want removed are </body> and </html> and are the last two lines in the HTML file.

I found similar topics, but none of them do what I need.

delete to end of line with SED

Thanks in advance for the help.
  #2 (permalink)  
Old 05-22-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Try this:

Code:
awk '/<\/body>/ || /<\/html>/{next}1' file
Regards
  #3 (permalink)  
Old 05-22-2008
dejavu88 dejavu88 is offline
Registered User
  
 

Join Date: May 2008
Posts: 18
It kinda works, but somehow I have to forward the output to a new file.

Code:
awk '/<\/body>/ || /<\/html>/{next}1' file.html > file2.html
is there a way to make it return the output to the original file? (file.html)

When I use:

Code:
awk '/<\/body>/ || /<\/html>/{next}1' file.html > file.html
I get a blank file.

All the code before the </body> and </html> tags should remain in the file.

Thanks
  #4 (permalink)  
Old 05-22-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
You can't redirect the output to the inputfile. Redirect the output to a temporary file and move it to the original file, something like this:

Code:
awk '/<\/body>/ || /<\/html>/{next}1' file.html > file1.html

mv file1.html file.html
Regards
  #5 (permalink)  
Old 05-22-2008
dejavu88 dejavu88 is offline
Registered User
  
 

Join Date: May 2008
Posts: 18
Just figured it out some minutes ago, same way like you wrote the code, before you replied. Thanks for all the help
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0