LING 408/508: Programming for Linguists Online Lecture 6 September 14 th.

Slides:



Advertisements
Similar presentations
Chapter 9: The TC Shell Everything you thought you knew is now wrong.
Advertisements

Find Command Characteristics –Locate files descending from multiple starting points –Employs regular expressions Examples On entire system: >find / -name.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Linux+ Guide to Linux Certification, Second Edition
Linux+ Guide to Linux Certification, Second Edition
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Using Linux Commands 2 Lab#5
Using Linux Commands 2 Lab#5. Sort command Sort the lines of text files. $ sort fileName by default it will sort in normal order(alphabetical 0-9 A-Z.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
Introduction to Shell Script Programming
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Linux+ Guide to Linux Certification, Second Edition
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Writing C-shell scripts #!/bin/csh # Author: Ken Berman # Date: # Purpose: display command and parameters echo $0 echo $argv[*]
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Computer Science 101 Introduction to Programming.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
Keyword Shell Variables The shell sets keyword shell variables. You can use (and change) them. HOME The path to your home directory PATH Directories where.
Basic Shell Scripting - Part 1 Objective - Learn to: Read Start-up Files Edit Start-up Files Modify Your User Environment Communicate with Users Write.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
LING 408/508: Programming for Linguists Lecture 4 September 2 nd.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Searching and Sorting. Why Use Data Files? There are many cases where the input to the program may come from a data file.Using data files in your programs.
(Re)introduction to Unix Sarah Medland. So Unix…  Long and venerable history  
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
LING 408/508: Programming for Linguists Lecture 8 September 23 rd.
(Re)introduction to Unix Sarah Medland. So Unix…  Long and venerable history  
Chapter Six Introduction to Shell Script Programming.
LING 408/508: Programming for Linguists Lecture 18 November 2 nd.
LING 408/508: Programming for Linguists Lecture 5 September 9 th.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Sed. Class Issues vSphere Issues – root only until lab 3.
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong. Homework 4 Submit one PDF file Your submission should include code and sample runs Due date Monday 21.
Linux+ Guide to Linux Certification, Second Edition
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
LING 408/508: Programming for Linguists Online Lecture 7 September 16 th.
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
Linux Administration Working with the BASH Shell.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
Lesson 5-Exploring Utilities
SUSE Linux Enterprise Desktop Administration
Shell Script Assignment 1.
What is Bash Shell Scripting?
LING 408/508: Computational Techniques for Linguists
CHAPTER 8 (skip , ) CHAPTER 10
LING 408/508: Computational Techniques for Linguists
LING 408/508: Computational Techniques for Linguists
LING 408/508: Computational Techniques for Linguists
Chapter Four UNIX File Processing.
LING 408/508: Computational Techniques for Linguists
Shell Programming.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
What is Unix? A multi-user networked operating system
Lab 2: Terminal Basics.
Introduction to Bash Programming, part 3
Presentation transcript:

LING 408/508: Programming for Linguists Online Lecture 6 September 14 th

Homework 4 Submit one PDF file Your submission should include all the numbered homework exercises Due date Monday 21 st September by midnight

Homework 4 Exercise 1 Write a bash shell script that simple accepts command line arguments and prints out the number of arguments, and each argument numbered on a separate line Examples: –bash args.sh a b c Args: 3 #1: a #2: b #3: c bash args.sh Args: 0

Homework 4 Exercise 2 Consider: –x=$(echo "scale=4;4*a(1)" | bc -l) –echo $x – (computes pi to 4 decimal places) Explain why –x=$((echo "scale=4;4*a(1)" | bc -l)) is wrong

rm CAUTION: do your test runs in VirtualBox for obvious reasons … rm can be used to delete files Example: –touch file1.jpg file2.jpg –rm file1.jpg file2.jpg by default, rm doesn't ask for confirmation. The interactive flag –i can be used for this purpose. It's a pain to have to always type rm –i, so the alias command can be use to always map r m onto rm –i as follows: –alias rm='rm –i' Test it this alias is considered dangerous: why?

Homework 4 Exercise 3 Note: – you have a startup file called. bashrc in your home directory – there are some default alias definitions in there Edit ~/.bashrc and add the alias for rm Logout and log back in Confirm that the alias is active (use: alias rm ) unalias can be used to remove aliases Confirm it works add the alias for rm back in alias can be side-stepped Run the command which rm Homework Question: How can you use this to deliberately side-step the rm alias you defined?

awk awk is a very useful command – it allows you process files line by line and extract matching information – Words on a line: $1 is word #1 in a line $2 is word #2 in a line (separated from #1 by space(s)) etc. – Some simple Awk code: print $3 means print word #3 in a line vname=0set variable vname to 0 (note: no $) (arithmetic expressions ok on the right side of the =, e.g. vname=vname+2) if (…) { … } else { … }conditional: e.g. $1 >= 3 ; separates statements – Syntax: awk 'BEGIN {..1.. } {..2.. } END {..3.. }' data.txt means execute awk code block {..1.. } at the beginning then process each line of data.txt using awk code block {..2.. } then at the end execute awk code block {..3.. } BEGIN {..1.. } is optional END {..3.. } is also optional man awk for examples

awk Example: – Top 30 surnames and percentages in the Canary Islands according to wikipedia – pe pe – Filename: surnames.txt (3 fields: rank, name, and percentage of population) Run the following awk code to figure out what the code does: 1.awk '{ print $2; }' surnames.txt 2.awk '{ if ($3>=1) {print $2;} }' surnames.txt

Homework 4 Exercise 4 Write awk code to: 1.print a table of and calculate the total percentage of population for the top 10, 20 and 30 surnames 2.read and print out the table with table headings aligned with the field values