Solved

# Script to parse the log file

Posted on 2014-09-19
315 Views
I have a text file with below contents. Need a shell or perl script that will take path to the scripts_folder as parameter

text file contents
==========================================================================

Repository: https://someserver:9443/
Workspace: (1000) "test_scripts_ws"
Component: (1001) "some_Automated_Scripts"
Change sets:
(1002) ---$john "test memory" 17-Sep-2014 02:24 PM Changes: --a-- \Libs\path\to\some\file22.txt --m-- \Libs\file\some\folder\locg2.lcke --d-- \Libs\file\in\some\folder\lock.lck ---c- \Libs\file\path\to\test\folder\source.mtr ---c- \Libs\Action1\Resource.mtr (1003) ---$ john "Test exist:"  17-Sep-2014 12
:33 PM
Changes:
---c- \Libs\path\to\some\folder\cript.mts
(1004) ---$john "Memory Fix #2" 17-Sep-2014 12:47 PM Changes: ---c- \Libs\path\tp\some\folder\test.txt ====================================================================================== The current folder structure is --&gt;test --&gt;scripts_folder --&gt;Libs --&gt;Libs2 --&gt;Libs3 --&gt;test1 test.pl C:\test\scripts_folder\ 1. Delete all the files in the scripts_folder directory except the one's in the above log file starting with --c- --a-- --m-- 2. Ignore lines starting with --d-- 3. Do not error out if the file matching above criteria is already deleted or doesnt exist in the scripts_folder directory. 0 Question by:gaurav sharma [X] ###### Welcome to Experts Exchange Add your voice to the tech community where 5M+ people just like you are talking about what matters. • Help others & share knowledge • Earn cash & points • Learn & ask questions • 2 • 2 4 Comments Author Comment ID: 40333355 For now I have : cat required.txt | grep -e --a- -e --m-- -e ---c- --a-- \Libs\test1\test1\test1.txt --m-- \Libs\test1\test1\test11.txt ---c- \Libs\Libs\test2\test2\test22.txt ---c- \Libs\Libs\test2\test2\test2.txt ---c- \Libs\Libs\test3\test33.txt 0 LVL 84 Expert Comment ID: 40333997 Is required.txt in the scripts_folder directory? If not, how should the script find it? If so, should it also be deleted? 0 Author Comment ID: 40336516 @Ozo: The required.txt is in the scripts_folder directory. This file should not be deleted. 0 LVL 84 Accepted Solution ozo earned 500 total points ID: 40348224 #!/usr/bin/perl use strict; use warnings; require 5.014; use File::Find; my($path,%r);
die "Usage: $0 pathtothescripts_folder" unless$path=shift;
chdir $path or die "$path $!"; ++$r{"/required.txt"};
open R,"<required.txt" or die "$path/required.txt$!";
while( <R> ){
++$r{$1=~s#[/\\]#/#gr} if /--(?:a-|m-|-c)-\s+(\S+)/;
}
close R;
find({wanted => sub{
!-f or $r{s#(^\.)?[\\/]#/#gr} or unlink$_ or warn "$_$!";
},no_chdir=>1},".");
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Title # Comments Views Activity
Problem to App 4 145
I could not set window to top 4 62
LINUX Field Separators 7 79
listing all the respondents to a twitter feed - Java 5 46
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Six Sigma Control Plans
###### Suggested Courses
Course of the Month6 days, 6 hours left to enroll

#### 734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.