Write a shell script named grepdir

Assignment Help Basic Computer Science
Reference no: EM13755871

1. Write a shell script, named grepdir.sh, that searches for a pattern in a directory, and all of its subdirectories.
The starting directory is the first argument, the pattern is the second parameter, and the options for grep are all succeeding parameter(s). Options will start with a hyphen. The script should produce a usage statement if the script is misused.

[davis@lect1 private]$ ls
cpdirs.sh grepdir.sh makemake.sh temp temp2 temp3 uncomp.sh
[davis@lect1 private]$ grepdir.sh cpdirs.sh bin
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh .
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh cpdirs.sh bin
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh .
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh . bin
#! /bin/bash
#! /bin/bash
#! /bin/bash
bin in file 1
#! /pkg/bin/bash
[davis@lect1 private]$ grepdir.sh . bin -l
./grepdir.sh
./cpdirs.sh
./makemake.sh
./temp2/1
./uncomp.sh
[davis@lect1 private]$ grepdir.sh . BIN -l
[davis@lect1 private]$ grepdir.sh . BIN -li
./grepdir.sh
./cpdirs.sh
./makemake.sh
./temp2/1
./uncomp.sh
[davis@lect1 private]$ grepdir.sh . BIN li
usage: grepdir.sh directory pattern [-grep option]*
[davis@lect1 private]$ grepdir.sh . BIN -n -i
1:#! /bin/bash
1:#! /bin/bash
1:#! /bin/bash
1:bin in file 1
1:#! /pkg/bin/bash
[davis@lect1 private]$

2. Write a shell script that copies the files in two directories dir1 and dir2 (supplied as the first two arguments), to dir3 (supplied as the third argument). If dir1 and dir2 contain the files with the same name, then the newer file should be copied to dir3. This does NOT look at the subdirectories of dir1 and dir2. Dir1 and dir2 must be existing directories, and dir3 may not be an existing regular file. The script should produce a usage statement if the script is misused. Name your script cpdirs.sh

[davis@lect1 private]$ ls -lR
.:
total 24
-rwx------ 1 davis users 533 2010-01-10 14:59 cpdirs.sh
-rwx------ 1 davis users 395 2010-01-10 14:39 grepdir.sh
-rwxr--r-- 1 davis users 980 2010-01-10 12:19 makemake.sh
drwxr-xr-x 2 davis users 4096 2010-01-10 15:01 temp
drwxr-xr-x 2 davis users 4096 2010-01-10 15:04 temp2
-rwx------ 1 davis users 384 2010-01-10 12:17 uncomp.sh
./temp:
total 0
-rw-r--r-- 1 davis users 0 2010-01-10 15:06 1
-rw-r--r-- 1 davis users 0 2010-01-10 14:44 2
-rw-r--r-- 1 davis users 0 2010-01-10 14:44 3.c
./temp2:
total 0
-rw-r--r-- 1 davis users 15 2010-01-10 15:04 1
-rw-r--r-- 1 davis users 4 2010-01-10 15:02 2
-rw-r--r-- 1 davis users 0 2010-01-10 14:44 3.cpp
-rw-r--r-- 1 davis users 4 2010-01-10 15:02 4
[davis@lect1 private]$ cpdirs.sh temp temp2 temp3
[davis@lect1 private]$ ls -l temp3
total 0
-rw-r--r-- 1 davis users 0 2010-01-10 15:08 1
-rw-r--r-- 1 davis users 4 2010-01-10 15:08 2
-rw-r--r-- 1 davis users 0 2010-01-10 15:08 3.c
-rw-r--r-- 1 davis users 0 2010-01-10 15:08 3.cpp
-rw-r--r-- 1 davis users 4 2010-01-10 15:08 4
[davis@lect1 private]$ cpdirs.sh temp temp2 temp3
[davis@lect1 private]$ ls -l temp3
total 0
-rw-r--r-- 1 davis users 0 2010-01-10 15:09 1
-rw-r--r-- 1 davis users 4 2010-01-10 15:09 2
-rw-r--r-- 1 davis users 0 2010-01-10 15:09 3.c
-rw-r--r-- 1 davis users 0 2010-01-10 15:09 3.cpp
-rw-r--r-- 1 davis users 4 2010-01-10 15:09 4
[davis@lect1 private]$ cpdirs.sh temp
usage: cpdirs.sh source_directory1 source_directory2 dest_directory
[davis@lect1 private]$ cpdirs.sh temp makemake.sh
usage: cpdirs.sh source_directory1 source_directory2 dest_directory
[davis@lect1 private]$ cpdirs.sh temp temp2 makemake.sh
usage: cpdirs.sh source_directory1 source_directory2 dest_directory
[davis@lect1 private]$3. (21 points) (30 minutes) Write a Bash shell script, makemake.sh, that will create a makefile called Makefile based on all the .cpp files in the current directory. If a .cpp file has any #includes of non-system header files (those with double quotes around them), then those files should be listed in its dependencies. The -Wall -ansi, and -g options will always be used with g++. The shell script takes the name of the executable as its first argument. If no argument is provided, the script should report the error, and print a usage statement. All other parameters are additional options that should be used with every call to g++. The Makefile should end with a "clean:" routine that removes the executable and all object files.

Do not use "*.o" in your clean routine. (Hints: the -n option of echo inhibits the default newline, and \t and \n work with echo. I used sed and awk to get at the name of the header files within the .cpp files.)
[davis@lect1 p2]$ ls
appointment.cpp calendar.cpp day.h dayofweek.h Lnk.c private time.h year.h
appointment.h day.cpp dayofweek.cpp Ins.c makemake.sh time.cpp year.cpp
[davis@lect1 p2]$ makemake.sh
Executable name required.
usage: makemake.sh executable_name
[davis@lect1 p2]$ makemake.sh cal.out
[davis@lect1 p2]$ make
g++ -ansi -Wall -g -c appointment.cpp
g++ -ansi -Wall -g -c calendar.cpp
g++ -ansi -Wall -g -c day.cpp
g++ -ansi -Wall -g -c dayofweek.cpp
g++ -ansi -Wall -g -c time.cpp
g++ -ansi -Wall -g -c year.cpp
g++ -ansi -Wall -g -o cal.out appointment.o calendar.o day.o dayofweek.o time.o year.o
[davis@lect1 p2]$ make clean
rm -f cal.out appointment.o calendar.o day.o dayofweek.o time.o year.o
[davis@lect1 p2]$ makemake.sh cal.out -O2 -g
[davis@lect1 p2]$ cat Makefile
cal.out : appointment.o calendar.o day.o dayofweek.o time.o year.o
g++ -ansi -Wall -g -o cal.out -O2 -g appointment.o calendar.o day.o dayofweek.o time.o
year.o
appointment.o : appointment.cpp appointment.h
g++ -ansi -Wall -g -c -O2 -g appointment.cpp
calendar.o : calendar.cpp year.h
g++ -ansi -Wall -g -c -O2 -g calendar.cpp
day.o : day.cpp appointment.h day.h dayofweek.h
g++ -ansi -Wall -g -c -O2 -g day.cpp
dayofweek.o : dayofweek.cpp dayofweek.h
g++ -ansi -Wall -g -c -O2 -g dayofweek.cpp
time.o : time.cpp time.h
g++ -ansi -Wall -g -c -O2 -g time.cpp
year.o : year.cpp year.h day.h
g++ -ansi -Wall -g -c -O2 -g year.cpp
clean :
rm -f cal.out appointment.o calendar.o day.o dayofweek.o time.o year.o
[davis@lect1 p2]$

Reference no: EM13755871

Questions Cloud

How was the communication effective : paper that applies three of the communication theories you have studied so far to your personal and/or professional life. For each theory you discuss, provide three examples of the theory at work in your life
Record the bad debts expense : Management estimates that 1% is the sales percentage to use. What adjusting entry will Hahn Company make to record the bad debts expense?
Compounding interest and the banker : There are many factors influencing the cost of money for both individuals and corporations. Suppose you deposit money in an interest bearing account and at the same time borrow a bit of money from the same bank.
Cost-volume-profit analysis : How does the firm use "Cost-Volume-Profit Analysis" to assess performance? How would you use such a system to measure how costs change as production changes? How do you develop a "break even analysis" for a given firm and how would you use it?
Write a shell script named grepdir : Write a shell script, named grepdir.sh, that searches for a pattern in a directory, and all of its subdirectories.The starting directory is the first argument, the pattern is the second parameter, and the options for grep are all succeeding paramet..
Financial reports required of all not-for -profits : What are the financial reports required of all not-for -profits? What additional report is required for voluntary health and welfare organization?
Research a security testing software tool : Research a security testing software tool that you practiced. Determine whether the tool would be beneficial in testing the security of a corporate network
Explain why openid offers users greater convenience : Explain why OpenID offers users greater convenience and security than the current system. Would you consider using an identity provider to access content on the Web? Why or why not
Explain the ethics of watergate and how it affected america : Explain the ethics of watergate and how it affected america.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Explain hardware to gather the essential information

Write down a 2-3 page paper explaining the hardware and software utilized to support personal, workgroup, and enterprise computing in the present organization.

  Compare the present value of economic profit

1. P15(d): Compare the present value of economic profit in each of the next three years and the loss of $50,000 in the third year using 15% as the discount rate.2. The spreadsheet problem (b): Calculate a mean, .... to statistically describe the data..

  Led paybyphone to switch to an ip-based network

What are the reasons that led PayByPhone to switch to an IP-based network?

  Capacity as a systems analyst

In your capacity as a systems analyst, you may face situations in which you encounter an ethical dilemma. For example, you may be asked to design a system that supports an activity with which you personally disagree

  Create class includes instance variables automatic propertie

Create a class called Employee that includes three pieces of information as either instance variables or automatic properties - a firstname (type string), a last name (type string) and a monthly salary (decimal)

  How to motivate the employees to accept the change

You began a group project where you had to rebuild/expand your company's information and communications technology infrastructure and information system.

  Write method determines pair integers whether multiple first

Write method multiple that determines, for a pair of integers, whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise.

  Create a short email message on the importance of a college

Email the message to your instructor using the email address provided by them and carbon copy an alternate email address (you can use your own address).

  What is big-o complexity of method

Write a method maxVal that accepts as parameter the reference to the head node of a linked list of integers. The method should return the largest value in the list. What is the Big-O complexity of the method maxVal?

  Design algorithm much more easily

As you will see when you complete the modular program design you will be able to add the new requirements to the design algorithm much more easily.

  Describe how these tips are implemented

Describe how these tips are implemented and why these are important.

  Describe an application

Can you compare the two? 3.Class templates are typically used to replace overloaded functions. Can you compare the two?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd