Skip to content
Snippets Groups Projects
Commit 04dfafe4 authored by Shane Do's avatar Shane Do
Browse files

Test

parent d055270e
No related branches found
No related tags found
No related merge requests found
Showing with 118 additions and 34 deletions
.DS_Store 0 → 100644
File added
No preview for this file type
File added
{\rtf1\ansi\ansicpg1252\cocoartf2638
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
Error: This is error 1 in log file
Error: This is error 2 in log file
Error: This is error 3 in log file
}
\ No newline at end of file
{\rtf1\ansi\ansicpg1252\cocoartf2638
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\f0\fs24 \cf0 Error: This is an error for multi test case 1\
}
\ No newline at end of file
{\rtf1\ansi\ansicpg1252\cocoartf2638
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\f0\fs24 \cf0 Error: This is a confirm for multi test case 2\
!}
\ No newline at end of file
File added
No preview for this file type
vm1.log: 283553
vm2.log: 267938
vm3.log: 268804
vm4.log: 270917
vm5.log: 271205
vm6.log: 268894
vm7.log: 268084
vm8.log: 274522
vm9.log: 269822
vm10.log: 265524
Total number of matching lines: 2709263
\ No newline at end of file
vm1.log: 0
vm2.log: 0
vm3.log: 0
vm4.log: 0
vm5.log: 0
vm6.log: 0
vm7.log: 0
vm8.log: 0
vm9.log: 0
vm10.log: 0
Total number of matching lines: 0
\ No newline at end of file
vm1.log: 1
vm2.log: 0
vm3.log: 0
vm4.log: 0
vm5.log: 0
vm6.log: 0
vm7.log: 0
vm8.log: 0
vm9.log: 0
vm10.log: 0
Total number of matching lines: 1
\ No newline at end of file
vm1.log: 84965
vm2.log: 80130
vm3.log: 80591
vm4.log: 81191
vm5.log: 81284
vm6.log: 80448
vm7.log: 80768
vm8.log: 82096
vm9.log: 80626
vm10.log: 79214
Total number of matching lines: 811313
\ No newline at end of file
vm1.log: 32473
vm2.log: 21726
vm3.log: 23171
vm4.log: 24521
vm5.log: 25238
vm6.log: 22684
vm7.log: 22013
vm8.log: 27898
vm9.log: 23753
vm10.log: 19447
Total number of matching lines: 242924
\ No newline at end of file
vm1.log: 2
vm2.log: 1
vm3.log: 1
vm4.log: 2
vm5.log: 0
vm6.log: 0
vm7.log: 1
vm8.log: 1
vm9.log: 0
vm10.log: 0
Total number of matching lines: 8
\ No newline at end of file
File added
...@@ -6,11 +6,12 @@ import java.util.List; ...@@ -6,11 +6,12 @@ import java.util.List;
public class Grep { public class Grep {
List<String> cmd = new ArrayList<>(); List<String> cmd = new ArrayList<>();
public Grep(String input) { public Grep(String input, String filePath) {
String cmd = "grep --color=always -w \"" + input + "\" GrepTest/test.rtf"; String cmd = "grep --color=always -c " + input + " " + filePath;
this.cmd.add("/bin/sh"); this.cmd.add("/bin/sh");
this.cmd.add("-c"); this.cmd.add("-c");
this.cmd.add(cmd); this.cmd.add(cmd);
} }
public List<String> run_cmd() throws IOException { public List<String> run_cmd() throws IOException {
...@@ -26,8 +27,9 @@ public class Grep { ...@@ -26,8 +27,9 @@ public class Grep {
System.out.println("Start reading logs!"); System.out.println("Start reading logs!");
//Fix this to return count of line matches //Fix this to return count of line matches
int ans = 0;
while ((line = input.readLine()) != null) { while ((line = input.readLine()) != null) {
System.out.println(line); // System.out.println(line);
res.add(line); res.add(line);
} }
......
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -8,10 +10,33 @@ public class main { ...@@ -8,10 +10,33 @@ public class main {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
System.out.println("Input regex matching for grep command: "); System.out.println("Input regex matching for grep command: ");
String input = sc.nextLine(); String input = sc.nextLine();
System.out.println("Input output file name: ");
String opt_filename = "Logs/Output/" + sc.nextLine();
List<String> output = new ArrayList<>(); List<String> output = new ArrayList<>();
BufferedWriter bw = new BufferedWriter(new FileWriter(opt_filename));
int total = 0;
for (int i=1 ; i <= 10; i++) {
String filePath = "Logs/Input/vm" + i + ".log";
Grep grep = new Grep(input, filePath);
output = grep.run_cmd();
String res = "vm" + i + ".log: " + output.get(0) +"\n";
System.out.println(res);
bw.append(res);
total += Integer.parseInt(output.get(0));
}
bw.append("Total number of matching lines: " + total);
bw.close();
// none => /faux.*/i
// all => http
// several => delete
// one => 244.142.133.185
// frequent pattern => "Jan.[0-9]\+"
// rare pattern => 9.123.164
Grep grep = new Grep(input);
output = grep.run_cmd();
//Fix this to return count of line mmatches //Fix this to return count of line mmatches
// for (int i=0; i<output.size(); i++) { // for (int i=0; i<output.size(); i++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment