Code-1:
Unix Terminal> cat find.pl
#!/usr/bin/perl
use strict;
use warnings;
# validating if the given argument has atleast 2 arguments passed
if (@ARGV < 2){
print "Invalid argument. Atleast two arguments must be passed", "\n";
print "Usage $0 <perlRegex> <List of files>", "\n";
}
# if all the required arguments are passed
else{
# if -i option is passed
if($ARGV[0] eq "-i"){
# taking regex and dir name into the variables
my ($regex, $dir) = ($ARGV[1], $ARGV[2]);
# capturing directory list
my @dirList = glob $dir;
# iterating through files in directory
foreach my $file(@dirList){
# flag variable to verify if the filename does not contain regex in its name or contents
my $flag = 1;
# capturing the filename without complete path
my $basename = (split /\//, $file)[1];
# if filename does not contain the regex given
if($file =~ /$regex/){
$flag = 0;
}
else{
# opening the file in read mode and checking if file does not have the required regex
open(FH, "<" , "$file") or die "$file cannot be opened: $!";
# flag variable to check if the given regex is not in entire file
while(my $line = <FH>){
if($line =~ /$regex/){
$flag = 0;
last;
}
}
close(FH);
}
# if filename does not contain the regex match or in its content then flag variable will be 1 otherwise 0
if($flag){
print $basename, "\n";
}
}
}
else{
# taking regex and dir name into the variables
my ($regex, $dir) = ($ARGV[0], $ARGV[1]);
# capturing directory list
my @dirList = glob $dir;
# iterating through files in directory
foreach my $file(@dirList){
# capturing the filename without complete path
my $basename = (split /\//, $file)[1];
# if filename contains the regex given
if($file =~ /$regex/){
print $basename, "\n";
}
else{
# opening the file in read mode and checking if file contains the required regex
open(FH, "<" , "$file") or die "$file cannot be opened: $!";
while(my $line = <FH>){
if($line =~ /$regex/){
print "$basename: $line";
last;
}
}
close(FH);
}
}
}
}
Unix Terminal>
Code output screenshot:
Code-2:
Unix Terminal> cat projectSorter.pl
#!/usr/bin/perl
use strict;
use warnings;
# validating if the given argument is atleast one argument passed
if (@ARGV != 1){
print "Invalid argument. One argument must be passed", "\n";
print "Usage $0 <directory>", "\n";
}
else{
# retreiving one argument which is dirname
my $dirname = $ARGV[0];
# getting list of files from the given directory
my @files = glob $dirname . '/*';
# iterating through each file in given directory
foreach my $file(@files){
# getting the basename of file without /
my $baseName = (split /[\/]/, $file)[1];
# retreiving the name before extension if filename contains proj*
if($baseName =~ /proj(.*)\./){
# creating a subdirectory from the filename
my $assign_name = $1;
my $sub_dirname = $dirname . "/" . "assignment" . $assign_name;
# creating a subdirectory
unless(-e $sub_dirname and -d $sub_dirname){
`mkdir $sub_dirname`;
}
# moving the file to sub directory
`mv $file $sub_dirname`;
}
# creating a directory misc if filename does not contains proj*
else{
my $sub_dirname = $dirname . "/" . "misc";
unless (-e $sub_dirname and -d $sub_dirname){
`mkdir $sub_dirname`;
}
`mv $file $sub_dirname`;
}
}
print "\n";
}
Unix Terminal>
Code output screenshot:
Project #6 Perl This assignment has two parts. Each part must be done using Perl Part...
Write a Perl script that accepts exactly 2 integer arguments
where the first argument must be less than the second argument. The
script will print a comma separated list of integers starting with
the first argument up through the second argument.
The last printed value should be the second command line
argument not be followed by a comma.
The script should also be able to handle the following
errorsituations:
o incorrect number of arguments
o the first...
Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents. Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...
In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string. The alphabet for generating DNA sequences is {A, T, G, C}. Write a regular expression that represents all DNA strings that contains at least two ‘A’s. Note: assume empty string is not a valid string. Design a deterministic finite automaton to recognize the regular expression. Write a program which asks the user...
Mini Project You are required to do this assignment on your own skills. No copying from other students are not allowed. Write a menu driven Bash script using the guidelines given below. Some of the commands and syntax may not be covered in lectures. Please refer other sources to understand syntax and commands you need to complete this assignment. This program takes user input and to perform simple arithmetic operations such as addition, subtraction, multiplication and division of any two...
/*hello everyone. my question is mostly related to the garagetest part of this assignment that i've been working on. i am not sure how to read the file's contents AND put them into variables/an array. should it be in an arraylist? or maybe a regular array? or no arrays at all? i am also not sure how to call the factory method from garagec. i'm thinking something along the lines of [Garage garage = new GarageC.getInstance("GarageC", numFloors, areaofEachFloor);] but i...
For this project, you are tasked with creating a text-based, basic String processing program that performs basic search on a block of text inputted into your program from an external .txt file. After greeting your end user for a program description, your program should prompt the end user to enter a .txt input filename from which to read the block of text to analyze. Then, prompt the end user for a search String. Next, prompt the end user for the...
C++ please
Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....
Overview: The goal of this assignment is to implement a simple spell checker using a hash table. You will be given the basic guidelines for your implementation, but other than that you are free to determine and implement the exact classes and methods that you might need. Your spell-checker will be reading from two input files. The first file is a dictionary containing one word per line. The program should read the dictionary and insert the words into a hash...
C++ There are to be two console inputs to the program, as explained below. For each input, there is to be a default value, so that the user can simply press ENTER to accept any default. (That means that string will be the best choice of data type for the console input for each option.) The two console inputs are the names of the input and output files. The default filenames are to be fileContainingEmails.txt for the input file, and...