Find/replace to new file: ksh -> perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find/replace to new file: ksh -> perl
# 1  
Old 05-16-2008
Find/replace to new file: ksh -> perl

I have korn shell script that genretaets 100 file based on template replacing the number.
The template file is as below:
Code:
$ cat template
file number: NUMBER

The shell script is as below:
Code:
$ cat gen.sh
#!/bin/ksh
i=1;
while ((i <= 100)); do
        sed "s/NUMBER/$i/" template > file_${i}
(( i = i + 1));
done

Now I want to migrate this code into perl script called gen.pl
How can I fine replace NUMBER is template file and generate new output file?
# 2  
Old 05-16-2008
Conveniently, Perl syntax is identical to sed syntax for this part.

Code:
s/NUMBER/$i/

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

2. Shell Programming and Scripting

Find and replace, perl code

Hi, Can somebody tell whats wrong with "find and replace perl code". I wanted to find "\n".write(status,data" and replace with "\n",data" in multipls files. #!/usr/bin/perl my @files = <*.c>; foreach $fileName (@files) { print "$fileName\n"; my $searchStr0 =... (4 Replies)
Discussion started by: chettyravi
4 Replies

3. UNIX for Dummies Questions & Answers

Perl find & replace - what am I doing wrong?

Hi! I have a directory full of .plist type files from which I need to delete a line. Not every file contains the line, but of course I'd like to do it recursively. The line which I want to delete is: <string>com.apple.PhotoBooth</string> and looks like this in its native habitat: ... (9 Replies)
Discussion started by: sudon't
9 Replies

4. Shell Programming and Scripting

Using sed in ksh to find and replace string

Hi All, I have a file in which contains location of various data files. I want to change locations using sed. Find and replace strings are in a separate file. Content of this file (/tmp/tt) - /dd/pp/test/test/1/ /pp/aa/test/dg1/ /dd/pp/test/test/2/ /pp/aa/test/dg2/ /dd/pp/test/test/3/... (2 Replies)
Discussion started by: pandeyra
2 Replies

5. Shell Programming and Scripting

Character Find and replace in Unix or Perl

Hi, I am stuck with an problem and want some help, what i want to do is There is a directory name temp which include file named t1.txt, t2,txt, t3.txt and so on. These files contains data, but there are some bad character also that is % present in the files , I want to write the script... (13 Replies)
Discussion started by: parthmittal2007
13 Replies

6. Shell Programming and Scripting

Have a find/replace perl script thats broke

Hello Folks, #!/usr/bin/perl use File::Find; open F,shift or die $!; my %ip=map/(\S+)\s+(\S+)/,<F>; close F; find sub{ if( -f ){ local @ARGV=($_); local $^I=""; while( <> ){ !/#/ && s/(\w+)\.fs\.rich\.us/$ip{$1}/g; print; } }... (8 Replies)
Discussion started by: richsark
8 Replies

7. Shell Programming and Scripting

perl find and replace

Hi, Please could someone advise, how I can resolve this issue with my find and replace command : perl -i -npe "s#RLM_LICENSE.*#RLM_LICENSE=$TEAM_TOP/licenses/abc.demo.lic#;" environment.properties $TEAM_TOP is an environment varible within my system. when i run this perl command from... (1 Reply)
Discussion started by: fettie
1 Replies

8. Shell Programming and Scripting

Find and Replace in ksh.

Hi Experts, I have a directory which have 500 ksh, they all have common path string. I have replaced all the ksh in different directory so i need to change the path string. Please help me how to search and replace it. Thanks SKG (1 Reply)
Discussion started by: gauravsunil
1 Replies

9. UNIX for Dummies Questions & Answers

how to use sed or perl command to find and replace a directory in a file

how to use sed command to find and replace a directory i have a file.. which contains lot of paths ... for eg.. file contains.. /usr/kk/rr/12345/1 /usr/kk/rr/12345/2 /usr/kk/rr/12345/3 /usr/kk/rr/12345/4 /usr/kk/rr/12345/5 /usr/kk/rr/12345/6 /usr/kk/rr/12345/7... (1 Reply)
Discussion started by: wip_vasikaran
1 Replies

10. Shell Programming and Scripting

Parentheses in perl find/replace

I'm trying to use the following command to do a batch find and replace in all commonly named files through a file hierarchy find . -name 'file' |xargs perl -pi -e 's/find/replace/g' which works fine except for a substitution involving parenthesis. As a specific example I'm trying to sub... (3 Replies)
Discussion started by: Jeffish
3 Replies
Login or Register to Ask a Question