LinuxQuestions.org
Review your favorite Linux distribution.
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,464

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: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
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: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 07:46 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration