LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-04-2013, 02:20 AM   #1
vivaa solutions
LQ Newbie
 
Registered: Jun 2013
Posts: 2

Rep: Reputation: Disabled
Thumbs up replace </para> to </p>


Can anyone help me to replace

I have a HTML file in that i want to replace

</para> to </p>
and
space? to ?space

I want to do it in perl script....

Last edited by vivaa solutions; 06-04-2013 at 02:33 AM.
 
Old 06-04-2013, 02:29 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
You don't give much information.
Do a search & replace operation.
1. Put </para> in the search field and </p> in the replace field. Click on "Replace all".
2. Put space? in the search field and ?space in the replace field. Click on "Replace all".
Since no one has any idea of what/where/when/how/why you want to do this it's hard to know what you're looking for.
Maybe you could go into a bit more detail of what you're trying to do and what steps you have taken to solve your problem.
jdk

Last edited by jdkaye; 06-04-2013 at 02:31 AM.
 
Old 06-04-2013, 02:35 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
For vars or strings, you could use Param Expansion
Code:
t='</para>'
echo ${t/ara}
</p>

t='space?'
echo ${t/space?/?space}
?space

# literal space
 t=' ?'
echo "=${t/ ?/? }="
=? =
For a file full maybe use sed instead
Code:
cat t.t
</para>
</para>

space?
space?

sed 's/ara//g' t.t
</p>
</p>

sed 's/space?/?space/g' t.t
</para>
</para>

?space
?space

# literal space
 cat t.t
</para>
</para>

 ?x
 ?x

sed 's/ ?/? /g' t.t
</para>
</para>

? x
? x
Obviously you can save each new version in a file to check before moving on.

Last edited by chrism01; 06-04-2013 at 02:37 AM.
 
Old 06-04-2013, 02:42 AM   #4
vivaa solutions
LQ Newbie
 
Registered: Jun 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
I TRY THIS CODE...BUT GIVES ERROR....CAN CORRECT IT

print "Enter the filename .ent without extention : ";
chomp($file=<STDIN>);
open(RED,"$file.ent");
open(WRIT,">$file.xml") || die "XML File already exit";
while(<RED>)
{
s/</para>"/"</p>"/g;
print WRIT $_;

}
close(RED);
close(WRIT);
 
Old 06-04-2013, 03:01 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You should have said you want Perl
Code:
 perl -ne 'print "$_\n" if s:</para>:</p>:' t.t
</p>

</p>
Incidentally, you should use this header
Code:
#!/usr/bin/perl -w
use strict;
& 3-arg open and check open did not fail
[code]
open(KFILE, "<", "kfile.txt" ) or
die "Can't open kfile: $!\n";

# close
close(KFILE) or die "Can't close kfile: $!\n";
[code]
Note the use of 'or' not '||'; its precedence thing.

I highly recommend you bookmark/read
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials
http://www.tizag.com/perlT/index.php
 
  


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
Para virtualisation looms Linux - Virtualization and Cloud 2 11-20-2009 01:02 AM
para virtualization question tanoatlq Linux - Software 7 05-09-2008 09:35 AM

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

All times are GMT -5. The time now is 01:12 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