Perl code request


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl code request
# 1  
Old 07-08-2013
Perl code request

Hi Perl Experts,

I am new to Perl programming.

can somebody please help me in writing Perl code for following "find and replace logic".

i wanted to find following line in list of files in a given directory.

================================================

Code:
for(i=0;i < temp1.temp2;i++) begin

================================================

and replace with following code.

================================================
Code:
j = temp1.temp2;

for(i=0;i < j;i++) begin

================================================

Thanks in advance,

Rgds,
Ravi.
Moderator's Comments:
Mod Comment Please use CODE tags.

Last edited by Don Cragun; 07-08-2013 at 03:43 AM.. Reason: Add CODE tags.
# 2  
Old 07-18-2013
I'd use sed, but there is a sed equivalent PERL substitute to change such a line. Do you know how to read a file line by line and write the lines to a second file?
# 3  
Old 07-19-2013
Code:
perl -pe 's/for\(i=0\;i < temp1\.temp2\;i\+\+\) begin/j = temp1\.temp2;\nfor\(i=0\;i < j\;i\+\+\) begin/g' file > outfile

if you want to overwrite the file, use -i option, (ex: 'perl -i -pe')
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Programming

Perl -- code

Hi All, I new to perl scripting, trying to write a program to get multiple inputs from the users and it should be stored in one variable. can some one help me with it . here is the sample code i tried , but its not working. # cat array.pl #!/usr/bin/perl print "enter the total no of... (4 Replies)
Discussion started by: nanduri
4 Replies

2. Shell Programming and Scripting

Request for horizontal formatting code

The input file contains 4 bytes per row 1 2 3 4 5 6 7 8 9 10 11 12 * * * 108 1 2 3 4 5 6 7 8 9 10 11 12 * * * 108 I need to put them in a horizontal manner and this need to repeat after every 108 lines lso the output comes as 1 2 3 4 5 6 7 8 9 10 11 12 ..... 108 1 2... (4 Replies)
Discussion started by: necro98
4 Replies

3. Programming

Perl- How to catch the file in perl code?

Hi, plz see the below code , i have catch the file "Orders.20110714.out "file as a Orders*.out. but it giving me an error .it does not open the file. if the same thing i have done by code code-> ls Orders*.out then it gives me the output Orders.20110714.out i am trying apply the... (1 Reply)
Discussion started by: pspriyanka
1 Replies

4. Shell Programming and Scripting

perl: a way to see a sub code in debug mode: perl -de 0 ?

Is there a way to see or print a sub code? Sometime a sub could be already defined, but in the debug mode (so, interactively) it could be already out of screen. So, I would think about a way to check if the sub is defined (just 'defined' is not a problem) and how it is defined. Also, if... (4 Replies)
Discussion started by: alex_5161
4 Replies

5. Shell Programming and Scripting

Request to code review Suggestions Plz

Hello All, I have 2 questions, 1) I am on Unix Sun Solaris korn shell, in my shell scripts i am using #!/bin/sh Instead of #!/bin/ksh, though it is still working is this correct way of doing and also I am saving the shell script file as abc.sh instead of abc.ksh, please let me know the best... (1 Reply)
Discussion started by: Ariean
1 Replies

6. Shell Programming and Scripting

checking the request for urls - perl

hi everybody . i'm trying to extract a bunch of urls from an http request but when i do that i get nothing . here it's my code use LWP::UserAgent; $url = "$ARGV"; $ua = LWP::UserAgent->new; $req = HTTP::Request->new(GET=>$url); $res = $ua->request($req); if... (0 Replies)
Discussion started by: KiD0
0 Replies
Login or Register to Ask a Question