Desperately Need Help On This Perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Desperately Need Help On This Perl script
# 1  
Old 10-02-2006
Desperately Need Help On This Perl script

ok, i dont know any perl. actually, very very little. not much at all.

now, the task i have is that i have to go into a directory that is packed with hundreds of files that contains lots of strings of which i have to filter through. so when i get into this directory, i type:

grep -r akamai * in the directory.


the above grep command spits out series of output similar to the below:

/excite/homepagepoll/ans_jan24_02.oft: <IMG SRC="http://a88.g.akamai.net/f/88/606/1d/image.lovesluudf.com/people/images/global/poll/popuptop.gif" WIDTH="468" HEIGHT="62" BORDER="0">


the path to the left of the colon of the above output represents the absolute path to the file in which the string i wanted is found.

now, my task is, i have to write a Perl script that will filter through the result of the "grep -r akamai *" and then produce a line that only contains the filename and the akamai string.

meaning, the resulting output should be something similar to:

/excite/homepagepoll/ans_jan24_02.oft: http://a88.g.akamai.net/f/88/606/1d/...l/popuptop.gif

basically, something that greps out the filename and the just the link(s) that is contained in that file which matches the "akamai"

sorry for the long read. but i just needed to clarify. someone please help. all i need is just something to get started with.
Terrible
# 2  
Old 10-02-2006
try this
Code:
grep -r akamai * | sed '/SRC=/s/\([^:]*\).*SRC="\([^"]*\)".*$/\1: \2/'

# 3  
Old 10-03-2006
Quote:
Originally Posted by anbu23
try this
Code:
grep -r akamai * | sed '/SRC=/s/\([^:]*\).*SRC="\([^"]*\)".*$/\1: \2/'


i'll give this a shot in a bit and let u know the results. i hope to god this works
Terrible
# 4  
Old 10-03-2006
nope it didn't work. is this anything else that can be done?
Terrible
# 5  
Old 10-03-2006
Try this.
Code:
grep -r akamai * | sed -n -e "s+^\([^:]*:\).*\(http[^\"].*\)\".*+\1 \2+p"

Not tested tho.
# 6  
Old 10-03-2006
Alternative in Python:

Code:
s = '/excite/homepagepoll/ans_jan24_02.oft: <IMG SRC="http://a88.g.akamai.net/f/88/606/1d/image.lovesluudf.com/people/images/global/poll/popuptop.gif" WIDTH="468" HEIGHT="62" BORDER="0">'
splitted = s.split(":",1)
homepage,  = splitted[0]
urlpage = splitted[1].split()[1].replace('SRC="',"").replace('"',"")
final = homepage + ":" + urlpage
print final

# 7  
Old 10-03-2006
Any use to you?
Code:
grep -q akamai * | nawk -F'[<"]' '{print $1$3}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Excuting perl script from within a perl script with variables.

Not sure what I am doing wrong here, but I can print the list with no issue. Just a blank screen with the 'do'. #!/usr/bin/perl open FILE, "upslist.txt"; while ($line=<FILE>){ if ($line=~/^(.*?),(.*?)$/){ #print "ups:$1 string:$2\n"; do 'check_snmp_mgeups-0.1.pl -H $1 -C $2'; } ... (1 Reply)
Discussion started by: mrlayance
1 Replies

3. Shell Programming and Scripting

Perl : embedding java script with cgi perl script

Hi All, I am aware that html tags can be embedded in cgi script as below.. In the same way is it possible to embed the below javascript in perl cgi script ?? print("<form action="action.htm" method="post" onSubmit="return submitForm(this.Submitbutton)">"); print("<input type = "text"... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Shell Programming and Scripting

executing perl script from another perl script : NOT WORKING

Hi Folks, I have 2 perl scripts and I need to execute 2nd perl script from the 1st perl script in WINDOWS. In the 1st perl script that I had, I am calling the 2nd script main.pl =========== print "This is my main script\n"; `perl C:\\Users\\sripathg\\Desktop\\scripts\\hi.pl`; ... (3 Replies)
Discussion started by: giridhar276
3 Replies

5. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

6. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

7. UNIX for Dummies Questions & Answers

UNIX advice needed desperately :/

Firstly I do need to state that I am turning here as a last resort. Im in my first year of a Computer Networking and technical support course, and as a first year I must complete a Introductory Unix/Linux class. I have been doing well in the course so far however I have been stumped on the final... (1 Reply)
Discussion started by: setaylor5
1 Replies

8. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

9. Shell Programming and Scripting

Help needed desperately

Hello Folks, i have written a script to nullify the log files in my dev environment but the log files are not getting nullified.Please find below my script and also thank you all in advance for your help. find /app -size +100000 -xdev -exec du -k {} \; 2>/dev/null | sort -nr |ls -1dF ... (2 Replies)
Discussion started by: Rayzone
2 Replies

10. Shell Programming and Scripting

Help needed desperately......

Hi guys, I want to execute an SQL script based on a condition.... I am writing a sample requirement... num = {some value} if(num == 0) then cat>> test.sql <<FIN select * from table_a FIN else cat>> test.sql << FIN select * from table_b FIN fi This is what i... (3 Replies)
Discussion started by: Payal Sharma
3 Replies
Login or Register to Ask a Question