473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

This must be done with perl isn't it?

Hello there,

I hope someone can help me.
This is my problem:
I have a list of thousands and thousands of the next lines:
----------------------------------------------------------------------
<a href="hs80.htm#halveringstijd"target="topic">halve ringstijd</a><br>
<a href="hs80.htm#hartkleppen" target="topic"></a><br>
<a href="hs80.htm#hartvolume" target="topic"></a><br>
<a href="hs80.htm#hemoglobine" target="topic"></a><br>
<a href="hs80.htm#heteroseksueel " target="topic"></a><br>
<a href="hs80.htm#hijgen" target="topic"></a><br>
<a href="hs80.htm#histamine" target="topic"></a><br>
--------------------------------------------------------------------------------------
I need to copy the word between the # and " and put it after the > and
</a>

It can done by hand like the first line but it can be automated with a
perl script isn't it?

If so I still have a problem can anyone tell me how?
TIA
Andries Meijer

Jul 19 '05 #1
3 1614
Andries wrote:
<a href="hs80.htm#hartkleppen" target="topic"></a><br>
I need to copy the word between the # and " and put it after the > and
</a>


Try to track down docs with useful perl one-liners. After studying
a few examples of '-pi.bak -e', you'll see your problem is very easy.

perl -pi.bak -e 's,#(\S+)(" target="topic">),#$1$2$1,' hs*.htm

-Joe
Jul 19 '05 #2
Andries <an*****@zilz.nl> wrote in message news:<b1********************************@4ax.com>. ..
Hello there,

I hope someone can help me.
This is my problem:
I have a list of thousands and thousands of the next lines:
----------------------------------------------------------------------
<a href="hs80.htm#halveringstijd"target="topic">halve ringstijd</a><br>
<a href="hs80.htm#hartkleppen" target="topic"></a><br>
<a href="hs80.htm#hartvolume" target="topic"></a><br>
<a href="hs80.htm#hemoglobine" target="topic"></a><br>
<a href="hs80.htm#heteroseksueel " target="topic"></a><br>
<a href="hs80.htm#hijgen" target="topic"></a><br>
<a href="hs80.htm#histamine" target="topic"></a><br>
--------------------------------------------------------------------------------------
I need to copy the word between the # and " and put it after the > and
</a>

It can done by hand like the first line but it can be automated with a
perl script isn't it?

If so I still have a problem can anyone tell me how?
TIA
Andries Meijer


Here's what I came up with, and I tested it with your samples, so it
seems to work just fine. You have to pass the input and output files
on the command line, so run it like this:

perl input_file.txt output_file.txt

Admittedly, I'm just getting back into PERL after a long break from
it, so if someone knows of a faster/more concise/more efficient way to
accomplish this task, I would be very interested in learning how you
did it.

Here's the code I came up with:

#!/usr/bin/perl -w

open(INPUT, "<$ARGV[0]") or die "Cannot open input file!\n";
open(OUTPUT, ">$ARGV[1]") or die "Cannot open ouput file!\n";
while(my $string_data = <INPUT>)
{
chomp $string_data;
@value = split(/([\#\"])/, $string_data);
printf OUTPUT "<a href=\"hs80.htm\#%s\"
target=\"topic\">%s</a><br>\n",$value[4], $value[4];
}

close(INPUT);
close(OUTPUT);
Jul 19 '05 #3
Andries <an*****@zilz.nl> wrote in message news:<b1********************************@4ax.com>. ..
Hello there,

I hope someone can help me.
This is my problem:
I have a list of thousands and thousands of the next lines:
----------------------------------------------------------------------
<a href="hs80.htm#halveringstijd"target="topic">halve ringstijd</a><br>
<a href="hs80.htm#hartkleppen" target="topic"></a><br>
<a href="hs80.htm#hartvolume" target="topic"></a><br>
<a href="hs80.htm#hemoglobine" target="topic"></a><br>
<a href="hs80.htm#heteroseksueel " target="topic"></a><br>
<a href="hs80.htm#hijgen" target="topic"></a><br>
<a href="hs80.htm#histamine" target="topic"></a><br>
--------------------------------------------------------------------------------------
I need to copy the word between the # and " and put it after the > and
</a>

It can done by hand like the first line but it can be automated with a
perl script isn't it?

If so I still have a problem can anyone tell me how?
TIA
Andries Meijer


#!/usr/bin/perl -w
while ( <> ) {
if ( /^([^#]+#)([^"]+)("[^>]+>)(.+)$/ ) {
print "$1$2$3$2$4\n";
}
}
__END__

run it as:
perl fix.pl < infile > outfile
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bob | last post by:
why is perl referred to as a CGI script and not php, php has the facility to execute backticked execute commands that enable the programmer to use operating system facilities as well ? why...
77
by: Hunn E. Balsiche | last post by:
in term of its OO features, syntax consistencies, ease of use, and their development progress. I have not use python but heard about it quite often; and ruby, is it mature enough to be use for...
5
by: NNTP | last post by:
#!/usr/bin/perl use Validate::Net; if ( Validate::Net->ip($ARGV)) { print "valid"; exit 0; } print "invalid"; #--done
4
by: Arthur | last post by:
Hi Everyone, I'm having a real hard time with this. Maybe some smarter people can assist. I'm running Mandrake 9.2. I have a Laserjet 4M Plus. I want to be able to print Postscript, bold,...
2
by: Alex | last post by:
Basically I want to parse some C++ source code and replace some constants. I've mangaed to read in the file and replace some of the things that need replacing. but I'm having a hard time...
11
by: Madison Kelly | last post by:
Hi all, I am new to the list and I didn't want to seem rude at all so I wanted to ask if this was okay first. I have a program I have written in perl which uses a postgresSQL database as the...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: Ant | last post by:
Hello! I am looking for a good hardcopy Perl book for newbies/beginners (including myself) who use Windows (not UNIX/Linux) and that isn't so old. After talking to my Linux friends who use Perl,...
31
by: happyse27 | last post by:
Hi All, I am doing a connection to database from perl to mysql via apache. Apache is configured correctly. Mysql username is root and password is mysql1, and database name is test. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.