substitution....
hi guys,
I have two files, ref.txt and replace.txt. replace.txt has 500 lines. I want to substitute a specific line in ref.txt with the 1st line of replace.txt and save the new file as 1.txt... similarly substitute that specific line in ref.txt with the 2nd line of replace.txt and save the new file as 2.txt... so finally i got 500 txt files. Plz help me to write a script for doing this(perl , shell or sed anything is ok..)? Plzzzz...... |
Homework ?
|
hey.... its not a homework??
|
Quote:
|
Quote:
Code:
ref = open('ref.txt') Code:
$ cat ref.txt Code:
if ref_line.strip() == 'replace me': Code:
if j == 3: uncomment it and use it how you want. if you want regex support then add in. Code:
import re |
Hi
thanks for your support. But actually i want the perl script. But in my script, I cannot write the output to a file after substitution. Plz help..... regards kadhan. |
Quote:
B. Since you have a script already, post it, and someone will help you out. |
Hi
sorry for the delay.... The code is given below... Code:
#!/usr/bin/perl and substitute the ref.txt file with the content in replace.txt..... But i cannot write the file after substitution.. I am a newbie in perl... so plz help me..... |
Personally I would not create a numerical directory name, it is bad practice and can lead to unexpected issues.
Therefore I suggest the following two changes to your Perl script: Code:
mkdir("dir_$count", 0777)|| print $!; Code:
unless (open(OUTFILE, "> dir_$count/outfile")) { |
HI,
Thanks for ur suggestion... But i dont get the answer for my question.....:cry: |
Quote:
For example, suppose you want to replace an entire constant line (e.g., 42) of ref.txt. Then you could do something like this: Code:
#!/usr/bin/perl Code:
#!/usr/bin/perl |
Why mess around w/ Perl, when sed can do the job:
Code:
REF='ref.txt' Like this: Code:
for N in $(seq -w 1 `cat replace.txt | wc -l`) Note 2: I did test the 1st example, but not the 2nd. |
Thanks....
Thanks......
Thanks ..... |
All times are GMT -5. The time now is 03:08 PM. |