Looking for a perl script (windows) to delete the contents of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looking for a perl script (windows) to delete the contents of a file
# 1  
Old 12-15-2008
Looking for a perl script (windows) to delete the contents of a file

Hi All,

Im having a file named logserver.txt. I want a perl script to take a backup of that file, along with the datestamp; move the file to a different location or empty the contents of the file after backup.

Remember, the file gets generated when the related service starts. My condition is that I should not stop the service to delete the file.

I have attached a perl script that I used for the above said. It takes a backup but not moving the file. Immediate help will be highly appreciated.

thanks,
Gobi
# 2  
Old 12-15-2008
"I should not stop the service to delete the file".

I'm not sure that's really possible, unless the service supports some kind of re-start mode. At any rate, if it DOES work, then instead of your "echo" line, try this one:
Code:
            $emptyfile=system("copy NUL: \"\" > \"$_\"");

In the UNIX shell, you'd do it in one of the following ways:
Code:
$ cat </dev/null >$outfile
$ dd if=/dev/null of=$outfile

# 3  
Old 12-15-2008
Otherwise, I would like to empty the contents of the file instead of deleting the file. Is it possible?
# 4  
Old 12-15-2008
Try the copy NUL: line.
# 5  
Old 12-16-2008
Its not working. Any other suggestion would be highly appreciated.
# 6  
Old 12-16-2008
Er, what part isn't working??
# 7  
Old 12-16-2008
I used copy nul as per the above reply and also tried system("echo.> logserver.txt"); Nothing works.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to Merge contents of 2 different excel files in a single excel file

All, I have an excel sheet Excel1.xls that has some entries. I have one more excel sheet Excel2.xls that has entries only in those cells which are blank in Excel1.xls These may be in different workbooks. They are totally independent made by 2 different users. I have placed them in a... (1 Reply)
Discussion started by: Anamika08
1 Replies

2. Shell Programming and Scripting

Perl script for Calling a function and writing all its contents to a file

I have a function which does awk proceessing sub mergeDescription { system (q@awk -F'~' ' NR == FNR { A = $1 B = $2 C = $0 next } { n = split ( C, V, "~" ) if... (3 Replies)
Discussion started by: crypto87
3 Replies

3. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

4. Shell Programming and Scripting

script to delete contents in a directory by date

Hi , I am trying to make a cron job to delete the contents of a directory in a linux environment.The contents created before 2 days should get deleted by this job.Here is what i have written : /usr/bin/find / -name *.log -ctime +2 -exec /bin/rm -f {} \; Is it correct....If not so,please... (9 Replies)
Discussion started by: d8011
9 Replies

5. Shell Programming and Scripting

Parse file contents in perl...

Hi, I have the file like this: #Contents of file 1 are: Dec 10 12:33:44 User1 Interface: Probe Dec 10 12:33:47 uSER1 SOME DATA Dec 10 12:33:47 user1 Interface: MSGETYPE Dec 10 12:34:48 user1 ID: 10. Dec 10 12:33:55 user1 Interface: MSGTYPE Dec 10 12:33:55 user1 Id: 9 ... (1 Reply)
Discussion started by: vanitham
1 Replies

6. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

7. Shell Programming and Scripting

how to read the contents of a file using PERL

Hi My requirement is to read the contents of a fixed length file and validate the same. But am not able to read the contents of the file and when i tried it to print i get <blank> as an output... I used the below satatements for printing the contents ... (3 Replies)
Discussion started by: meva
3 Replies

8. Shell Programming and Scripting

Perl script to copy contents of a web page

Hi All, Sorry to ask this question and i am not sure whether it is possible. please reply to my question. Thanks in advance. I need a perl script ( or any linux compatible scripts ) to copy the graphical contents of the webpage to a word pad. Say for example, i have a documentation site... (10 Replies)
Discussion started by: anand.linux1984
10 Replies

9. Shell Programming and Scripting

How can i delete the contents of one file based on another file

Hi all, I have two log files A and B. Where files A have 10 lines and file b has 5 lines. Out of them 3 lines are common to both of them. I want to compare both the files and want to delete the common data from file A(file B should remain as it is) example : file A : 1 2 3 4... (5 Replies)
Discussion started by: rdhanek
5 Replies
Login or Register to Ask a Question