Name: ______

Homework4: Shell Scripting Due: Nov. 1st

Bash:

1. Write a bash shell script that takes a file name and a character string as argument, tests for the files existence, then reports if the file does not exist or the number of lines in the file with the character string. Use this script to look for the string “ARGENTINA” in the file ~hdeshon/ESCI7205/samgps.dat. (You do not have to copy the file from my directory; you should be able to access it from your account.)

The command to execute the shell script, and its possible outputs, will look something like this

%myscript ~hdeshon/ESCI7205/sampgps.dat ARGENTINA

the file ~hdeshon/ESCI7205/sampgps.dat does not exist

%

%myscript ~hdeshon/ESCI7205/samgps.dat ARGENTINA

the file ~hdeshon/ESCI7205/samgps.dat has 100 lines with the string (ARGENTINA)

Directory and name of file: ______

Csh:

2. Copy the file netdc.quick.csh from ~hdeshon/bin to your current homework directory. Copy the file sample.eventlist from ~hdeshon/ESCI7205.

a) What shell syntax is being used in netdc.quick.csh file? Is this script interactive or non-interactive?

b)Describe this program in your own words. What do you think this does? Remember, NetDC is a data request system that allows a user to request seismological information from multiple data centers through a single email mechanism.

c) Run the script using the following parameters:

label for request file: Test

name of event file: sample.eventlist

networks (* for all): IU

stations (* for all): AAK

channels (* for all): BHZ

time window (minutes after origin): 20

What is the output file name? ______

Using Awk:

3. Using awk, remove the geographical location information (city, state, etc) from the NMSZ.catalog.vim file you created for Homework 1. You should be left with the magnitude, origin time, latitude, longitude, and depth. Rearrange that information so that it appears in the following order with tab separation:

Origin TimeLatitude LongitudeDepth Magnitude

Redirect the output to a new file called NMSZ.catalog.final

a) Document the list of awk command(s) you used to create this file:

b) Write an awk script that

i) approximately identifies which arm of seismicity the earthquake is associated with and prints this information at the end of each hypocenter line. I have provided the approximate latitude/longitudes of each arm of seismicity and the expected identification text below.

ii) calculates the mean latitude, longitude, depth, and magnitude of all events in the file NMSZ.catalog.final and outputs this information after part i.

iii) calculates the mean latitude, longitude, depth, and magnitude of events along each arm of seismicity and outputs this information after part ii.

Directory with script: ______

Modifying a script to do what you need:

4. Copy the script ~hdeshon/ESCI7205/myfirstmap.sh and the data file ~hdeshon/ESCI7205/eqs.vim to your homework directory.

a) Run the script (you should not have to make any changes). What is the name of the output file? Use the command “gs” to display the map you made. Explain in detail what each line of the shell script does and what the options/flags/switches on the GMT programs pscoast and psxy do. Use man pages!

b) Go to the web page - - select rectangular area. On the page that opens select the options “screen file format”, “USGS/NEIC (PDE) 1973-present”, and put in a latitude and longitude range to cover the continental United States. Using the editor of your choice, cut and paste this information into a file in your homework directory.

c) Modify the script myfirstmap.sh (call it something else - don’t erase the original) to make a map using the new data set from 4b. You will have to modify the region plotted, the scale, and the input file handling as a minimum. Also, change the color of the earthquakes to red. Print and turn in your new map.

Directory with script: ______

1