Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# ! / bin / bash #Author: Name #Purpose: This script processes a data file to produce 5 output files based on specified criteria #Check

#!/bin/bash
#Author: Name
#Purpose: This script processes a data file to produce 5 output files based on specified criteria
#Check if a file name is provided
if [[ $# ==0]]
then
echo Usage: $0""
exit 1
fi
inputFile="$1"
#Task 1: Add a header and output the data to move1.txt
echo "Name Phone Number Jan Feb Mar" > move1.txt
cat "$1">> move1.txt
#Task 2: Duplicate the file, replace "John" with "Mary, and save to move2.txt
sed 's/John /Mary /g'"$1"> move2.txt
#Task 3: Extract donors with area code 888 and save their names to move3.txt
grep '(888)'"$1"| sed 's/%.*//'> move3.txt
#Task 4: Extract first names of donors whose last name starts with M or N
grep '[MN]'"$1"| sed 's/.*//'> move4.txt
#Task 5: Find people who donated at least $10.00 in any month, save their name and number, sorted by last name
grep -e '\$[0-9][0-9][]*'| sed 's/%$.*//'| sed 's/%/%/g'| sort -k2| sed 's/%/%/g'> move5.txt
Attention! In the beginning of each program (Bash script file), after #!/bin/bash line, there should be comments with the authors name and the the purpose of the script. Up to 3 points will be subtracted from your score for each part of the project if you dont include this information.
[30 points] Write a Bash shell script named move.sh.
This script will be working with a data file named as the first argument to your script, so you would run it with the command:
./move.sh someFile.txt
if I wanted it to work with the data inside the file someFile.txt.
The ending result will be it producting 5 files, move1.txt through move5.txt.
The data files your script will work with will contain lines in the following format:
Jane Smith%(314)314-1234%$10.00%$50.00%$15.00
Mark Hauschild%(916)516-1234%$5.00%$75.00%$25.25
which indicate the amount someone donated in a particular month (over a 3 month period).
Note that the actual file will contain other names, phone numbers and amounts. You can assume that any names will have a first and last name only, with only alphabetic characters.
I want your script to do the following tasks and save the resulting data in the locations asked.
Note: These tasks do not have to be done in one single command. They can be done in a series of commands working on different files, or piped from one command to another. In fact, I would suggest breaking the task up if that would make some of them easier.
1) Output the data to a new file, adding a header to it and send that data to a file called move1.txt.
This head should be as follows:
Name Phone Number Jan Feb Mar
2) Duplicate the file in a file called move2.txt, except replace any names of "John" with "Mary"
3) Put the list of donors (only their names, no other data) with area code 888 in a file called move3.txt
4) Anyone who's last names start with a M or N should go into a file called move4.txt, but only their first names.
5) Find the people who donated at least $10.00 in any month in the file move5.txt. For this, I just want their full name and phone number, but nothing else. This data should be sorted by their last name.
5 points for each task finished. Note that you can do each of these tasks in more than one command if you like, but the end result should be the files move1.txt - move5.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions