LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   replace </para> to </p> (https://www.linuxquestions.org/questions/linux-newbie-8/replace-para-to-p-4175464639/)

vivaa solutions 06-04-2013 02:20 AM

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....

jdkaye 06-04-2013 02:29 AM

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

chrism01 06-04-2013 02:35 AM

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.

vivaa solutions 06-04-2013 02:42 AM

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);

chrism01 06-04-2013 03:01 AM

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


All times are GMT -5. The time now is 02:18 AM.