LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-02-2004, 09:37 AM   #1
ledauphin
LQ Newbie
 
Registered: Mar 2004
Location: GERMANY
Posts: 2

Rep: Reputation: 0
how to replace html-file-content ???


hi script-freaks,
i'm trying to remove the last 8 lines of an html-file and replace them by new 4 lines.

characteristics of the html-file: there exists some table-tags in the file, but the last table should be replaced by something new (e.f. a link to another homepage).

i would like to do this by script, but i'm really new in scripting.
could you please help me???

i think, this should go with "sed", but i'm not sure.

thanks a lot
tom
 
Old 03-02-2004, 01:54 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Welcome to LQ.

You never gave a language so I'll assume you mean in a shell - try:
#!/bin/bash
# Remove the last 4 lines
cat /path/to/file.html | tail -n $((`cat /path/to/file.html | grep -c ""`-4))
# Add 4 new ones
echo -e "line 1\nline2\nline3\line4" >> /path/to/file.html
 
Old 03-08-2004, 04:37 PM   #3
ledauphin
LQ Newbie
 
Registered: Mar 2004
Location: GERMANY
Posts: 2

Original Poster
Rep: Reputation: 0
hi david,

thanks for your comment (very good suggestion for me) !!!

meanwhile, i did it this way:

i count the lines if the html-file, remove the last 8 lines (with head) => read my new "end-of-file" from a source file (it's always the same) and add this to the cutted html-file.

regards
ledauphin
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML for semi-static content? MaTrIx709 Programming 4 08-07-2005 05:07 AM
Replace text of unknown content with other text in file brian0918 Programming 15 07-14-2005 09:22 PM
Replace text of unknown content with other text in file brian0918 Linux - Software 1 07-14-2005 03:22 PM
php question - how can i replace the content? antony_csf Programming 2 06-29-2004 08:01 PM
use CGI vs. content-type: text/html johnensd Red Hat 0 05-09-2004 11:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration