editing single line in html file in perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting editing single line in html file in perl script
# 1  
Old 08-06-2012
editing single line in html file in perl script

Hi Folks,

It is regarding the perl scripting.

I have an html file(many files) which contains the below line in the body tag.
Code:
<body>
<P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P>
</body>

Now I want to read that html file through perl script and edit the html file by changing the text from Hello to Hello Giridhar and the other text remains same.This tag is in exactly 8th line in the html file

After running the scipt, if I open the html file than the text "Hello Giridhar" has to be displayed instead of Hello.

Could you please share your ideas on this ?

Thanks in advance..

Regards,
Giridhar


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-06-2012 at 05:21 AM.. Reason: code tags
# 2  
Old 08-06-2012
Hi

Code:
$ perl -pne 's/Hello/Hello Giridhar/ if($.==8)' file

Guru
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 08-06-2012
Many thanks Guruprasad...

I do have a small change here..
In my perl script, the name keeps on changing in the loop based on the parameters passed to the script.

Could you please let me know the code based on the above condition.

Regards,
Giri
# 4  
Old 08-06-2012
Quote:
Originally Posted by guruprasadpr
Hi
Code:
$ perl -pne 's/Hello/Hello Giridhar/ if($.==8)' file

Guru
@guruprasadpr: Option n is not required if p is used. In crude terms, Option p = Option n + print.

@giridhar276:Here's a bash script:
Code:
#! /bin/bash

for htmlFile in *.html
do
    sed -i "8s/Hello/$1/" $htmlFile
done

To run, give the name as argument to script
Code:
$ ./test.sh Giridhar


Last edited by balajesuri; 08-06-2012 at 05:53 AM..
This User Gave Thanks to balajesuri For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tabbed multiple csv files into one single excel file with using shell script not perl

Hi Experts, I am querying backup status results for multiple databases and getting each and every database result in one csv file. so i need to combine all csv files in one excel file with separate tabs. I am not familiar with perl script so i am using shell script. Could anyone please... (4 Replies)
Discussion started by: ramakrk2
4 Replies

2. Shell Programming and Scripting

Editing path in a HTML file using Perl

Hello I want to replace the path to which a hyperlink points to. I have a html file <TABLE BORDER CELLPADDING=7, border=0><TR><td>Jun-10-2013_03_19_07_AM</td><td>Ank_Insert_1</td><td><b>FAILED: 1</b></td><td><A ... (14 Replies)
Discussion started by: ankurk
14 Replies

3. Shell Programming and Scripting

Shell script - Replace just part of a single line in a file.....

Hey guy's.... I new here, But im working on a school project, and I am not really good at programming. In fact, this is the only programming class that I need because programming is not what I am majoring in. But I have everything done in this shell script except for this last part..... ... (9 Replies)
Discussion started by: hxdrummerxc
9 Replies

4. Programming

PERL:Combining multiple lines to single line

Hi All I need a small help for the below format in making a small script in Perl or Shell. I have a file in which a single line entries are broken into three line entries. Eg: I have a pen and notebook. All i want is to capture in a single line in a separate file. eg: I have a pen and... (4 Replies)
Discussion started by: Kalaiela
4 Replies

5. Shell Programming and Scripting

How to use Perl to join multi-line into single line

Hello, Did anyone know how to write a perl script to merge the multi-line into a single line where each line with start at timestamp Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; (5 Replies)
Discussion started by: happyday
5 Replies

6. Shell Programming and Scripting

How to use Perl to merge multi-line into single line

Hi, Can anyone know how to use perl to merge the following multi-line information which beginning with "BAM" into one line. For each line need to delete the return and add a space. Please see the red color line. ******Org. Multi-line) BAM admin 101.203.57.22 ... (3 Replies)
Discussion started by: happyday
3 Replies

7. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

8. Shell Programming and Scripting

Script to add a single line to middle of text file.

I've got a configuration file that is filled with xml text statements for example: <...../> <...../> <...../> <data id="java-options" value="-server -Djava.security.policy..../> <...../> <...../> <...../> I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies

9. Shell Programming and Scripting

Single line file editing command?

Hello everyone. I have been reading a lot about the various different text editors at my disposal through Unix, but I just can't seem to close the deal for what I am trying to do. Is there a way to issue a single line command to edit a file where pattern=x, and do it non-destructively AND in-place?... (1 Reply)
Discussion started by: gator76
1 Replies

10. UNIX for Advanced & Expert Users

Can't Editing File in Single mode (using vi)

Dear All, Yesterday I'm change /etc/vfstab file ( disable 1 Device mounting) and now I can't login to multiuser mode just single user mode, and now I want enable again, but I can't using vi editor in single user mode How to edit this file? thereis default can't using vi editor in single mode?... (14 Replies)
Discussion started by: heru_90
14 Replies
Login or Register to Ask a Question