Name: _____________________________________________________ Homework 4: 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. 1 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 Time Latitude Longitude Depth 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: ___________________________________________________________________ 2 Boxes defined by a minimum and maximum latitude and longitude: North Arm (NA): 36.6, 36.9 -89.55, -89.25 Northwest Arm (NWA): 36.5,36.7 -90.1, -89.7 Central Arm (requires two boxes): CA1: 36.25, 36.7 -89.7, -89.55 CA2: 36.0, 36.6 -89.55, -89.25 South Arm (SA): 35.5, 36.25 -90.75, -89.55 Any event that does not fall within each of the above boxes should be identified as “Outside the areas of interest” 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 - http://earthquake.usgs.gov/earthquakes/eqarchives/epic/ - 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. 3 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: _______________________________________________________________________ 4