Sponsored Content
Top Forums Shell Programming and Scripting Perl : Delete all files except few Post 302885570 by gaurav99 on Monday 27th of January 2014 11:29:21 AM
Old 01-27-2014
Perl : Delete all files except few

I have a directory like below. Need help with Perl to delete all files under test1 except the one passed as parameters.The parameters will
always be the directories under test1 in the format below.

EX:
Code:
dir1/abc.txt,dir2/test.xml,dir3/dfb.txt,dir4/text.xml


Code:
test1  
            ---dir1
                  abc.txt
                  def.txt
                  test.xml
                  test.csv
                  test.xml
            ---dir2
                  fgh.txt
                  jhk.txt
                  test.xml
                  test.csv
                  test.xml                   
            ---dir3
                  rth.txt
                  dfb.txt
                  test.xml
                  test.csv
                  test.xml
            ---dir4 
                  ert.txt
                  def.txt
                  test.xml
                  test.csv
                  test.xml

Did not find negation for unlink in perl.Smilie

Last edited by bartus11; 01-27-2014 at 05:04 PM.. Reason: Please use CODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

2. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

3. Shell Programming and Scripting

delete last row in PERL

How to delete last row in the file in PERL. file1 has a.output b.output c.output d.output e.output expected output is a.output b.output c.output d.output (1 Reply)
Discussion started by: adaleru
1 Replies

4. Shell Programming and Scripting

How to delete newline with perl

input: donkey monkey dance drink output should be: donkey monkey (8 Replies)
Discussion started by: cola
8 Replies

5. Shell Programming and Scripting

delete a file using perl

Hi, How to delete a file (if exists) using perl script. I have used following script.. if ( -e $newfile) { open (FILE, ">$newfile") || die "Cannot Open File\n"; print FILE; close(FILE); } But it gives me error "Use of uninitialized value in print". please help. Thanks in... (1 Reply)
Discussion started by: arup1980
1 Replies

6. Shell Programming and Scripting

Delete files in directory using perl

Hello All I am implementing my task in Perl and i found an issue. What i want to do is to remove files from the directory which were made 20 days back using Perl script (9 Replies)
Discussion started by: parthmittal2007
9 Replies

7. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

8. Shell Programming and Scripting

Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All, I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet #Script Starts here #!/usr/local/bin/perl #Program to find the disk space and to delete the older files #Checks the type of OS... (8 Replies)
Discussion started by: arunkarthick
8 Replies

9. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

10. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies
xmltest(1)						      General Commands Manual							xmltest(1)

NAME
xmltest - Test script to send CIM-XML (via wbemcat) to CIMOM and compare to known results SYNOPSIS
xmltest [FILE] DESCRIPTION
xmltest is a script that is used to send a raw CIM-XML test file to the sfcb CIMOM (using wbemcat) and then compares the returned CIM-XML results against a previously determined 'OK' result file to check whether the returned results match the expected results. If there does not yet exist an 'OK' corresponding to the XML file then xmltest will save the returned results as the new OK file for later use. If the returned CIM-XML results don't match the existing 'OK' file a new 'result' file will be generated containing the erroneous results. If no FILE is specified xmltest will use all files with a .xml extension in the current directory path. EXAMPLE
If there is no 'OK' file to compare returned CIM-XML results against xmltest will generate one. # xmltest test/getclass.Linux_OperatingSystem.xml Running test test/getclass.Linux_OperatingSystem.xml ... OK Saving response as test/getclass.Linux_OperatingSystem.OK If the returned CIM-XML results match the existing 'OK' file xmltest will signal that the test passed. # xmltest test/getclass.Linux_OperatingSystem.xml Running test test/getclass.Linux_OperatingSystem.xml ... Passed If the returned CIM-XML results don't match the existing 'OK' file xmltest will signal that the tes failed and generate a 'result' file containing the erroneous results. # xmltest test/getclass.Linux_OperatingSystem.xml Running test test/getclass.Linux_OperatingSystem.xml ... FAILED Check test/getclass.Linux_OperatingSystem.result for errors PREREQUISITES
Requires wbemcat on search path. AUTHOR
Dr. Gareth S. Bestor <bestor@us.ibm.com> CONTRIBUTORS
Adrian Schuur <schuur@de.ibm.com> BUGS
Does not adequately deal with additional http headers/footers caused by chunking responses, which will result in false failures when com- paring results to existing "x.OK" files. The SBLIM project maintains a mailing list to which you should direct all questions regarding sfcb, sfcc, wbemcli, or any of the SBLIM providers. To subscribe to this mailing list visit http://lists.sourceforge.net/lists/listinfo/sblim-issues The SBLIM Project Bug tracking page can be found at http://sourceforge.net/tracker/?group_id=128809&atid=712784 COPYRIGHT
(C) Copyright IBM Corp. 2004, 2005 AVAILABILITY
The Small-Footprint CIM Broker (sfcb) is a part of the SBLIM project. The most recent version is available on the web at http://sblim.sourceforge.net/ SEE ALSO
wbemcat(1) xmltest Version 1.3.16 August 2005 xmltest(1)
All times are GMT -4. The time now is 07:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy