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
# 8  
Old 12-16-2008
Yes, but what is not working? Are you saying the file never gets overwritten, or that the new file contains zero bytes but is never appended to after that?
# 9  
Old 12-16-2008
Yes, the file never gets overwritten.
# 10  
Old 12-16-2008
Well, assuming you have the correct pathname for the file, it would seem to be a windows thing.
# 11  
Old 12-16-2008
I tried using system("echo.> logserver.txt"); and I got the message as "The process cannot access the file because it is being used by another process."

Later, I opened the txt file and deleted the contents manually and saved it on the same place. It asked me whether to replace the existing file and I clicked Yes. This time, it got saved and the file size was 0 bytes. My question is when Im able to do it manually, why the script gives an error message? Please see that I didnt stop the service when I deleted the content and saved the file.
# 12  
Old 12-16-2008
I'm sorry, it's a Windows thing. Windows probably has some kind of mandatory file locking mechanism. In UNIX it's generally advisory (optional). Maybe search the net and the Perl-Windows ports for dealing with "file locking"
# 13  
Old 12-16-2008
Thanks for your valuable inputs. I will try searching in the net.
# 14  
Old 12-23-2008
Quote:
Later, I opened the txt file and deleted the contents manually and saved it on the same place.
Could be when you open it later the file is no longer in use by another process. Windows does not allow files that are in use by certain processes to be opened more than once. There is no way around it that I know of.
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