Understanding Unix and shell scripting are very useful tools that can work alongside your developing Python knowledge. In this lab you will exercise some of the commands we discussed in lecture, gain experience with using/understanding the manual pages for other commands, and write some simple shell scripts.
~/geop501/lab08
)Copy the lab08 files into this directory and unpack them:
$> tar xf lab08_files.tar
Use the following commands:
a) date
: print out the current date and time in seconds in Epoch time (since 00:00:00 UTC Jan 1, 1970)
b) cat
: put contents of file1
and file2
sequentially together into a new file file3
.
c) touch
: create a new file unless it already exists
d) split
: break a 500-line file (largefile.txt
) into multiple files that each have 50 lines
e) sort
: sort a file on the first column in largefile2.txt
and write only the non-repeating lines to a new file
f) uniq
: print out only the non-repeating lines in the largefile2.txt
Please submit the commands and their output as a separate, well-commented deliverable (text file, for instance).
lab8_station_list.txt
.First, using Unix tools, describe the contents of this file (what do you think it contains, how is it structured, how many lines, how many characters). Provide the commands that you use to figure this out.
a) Write down 1 line of Unix commands that allows you to view the first 20 lines of file lab8_station_list.txt
(station_name latitude longitude
) and pipe the output of this
into another command that can count the lines and show that, indeed, we have 20 lines.
b) Write down 1 piped sequence of commands to view a sorted version of the last 10 lines of the same file. Sort by station name in column 1.
c) Write down 1 piped sequence of commands that you would use to view the 15 northern-most station in that file.
Use the simple tcsh script below (copy it into a file lab8_script4.sh
and change
permissions to be executable [figure out how from past labs if you don't remember]). Add comments
to each line explaining what it is doing, and provide a commented line at the end of the script
that describes the output you get when running the script.
#!/bin/tcsh set directory=~/geop501/lab08 cd $directory pwd ls ls | wc -l
lab8_script5.sh
Using either bash or tcsh, write a shell script that:
~/geop501/lab08
directory check the filenames below and provide the output of your program.
lab8_station_list.txt lab8_section6.txt lab8_section7.txt
Now copy your shell script from task 6 into a new file named lab08_script7.sh
, such that it:
$> lab08_script7.sh stations.txt
Now copy your shell script from task 7 into a new file named lab08_script8.sh
and
make the latitude longitude box a command line argument to both, the shell script lab08_script8.sh
and the python script, such that we can call:
$> lab08_script8.sh stations.txt 32 34 -106 -103
rg <at> nmt <dot> edu | Last modified: November 05 2017 01:27.