Shell Scripting Basics Arun Sethuraman. What’s a shell? Command line interpreter for Unix Bourne (sh), Bourne-again (bash), C shell (csh, tcsh), etc Handful.

Slides:



Advertisements
Similar presentations
Linux commands exercise 1. What do you need, if you try to these at home? You need to download and install Ubuntu Linux from the Internet – DVD is need.
Advertisements

Shell Script Assignment 1.
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Very Quick & Basic Unix Steven Newhouse Unix is user-friendly. It's just very selective about who its friends are.
Shell Script Examples.
CSCI6303 – Principles of I.T. Fall  Student will become familiar with scripting in shell using Linux/Ubuntu  Student will write a script and execute.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Review for Exam 1 Exam 1 on June 24 CSC 3320.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Using the Unix Shell There is No ‘Undelete’. The Unix Shell “A Unix shell is a command-line interpreter or shell that provides a traditional user interface.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Alistair Chalk, Elisabet Andersson Stem Cell Biology and Bioinformatic Tools, DBRM, Karolinska Institutet, September Bioinformatics Primer.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Unix Basics Chapter 4.
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
Dedan Githae, BecA-ILRI Hub Introduction to Linux / UNIX OS MARI eBioKit Workshop; Nov , 2014.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
L&T Infotech1 UNIX – Getting Started - Aneesh Ramani.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
(Re)introduction to Unix Sarah Medland. So Unix…  Long and venerable history  
Getting the most out of the workshop Ask questions!!! Don’t sit next to someone you already know Work with someone with a different skillset and different.
40 Years and Still Rocking the Terminal!
(Re)introduction to Unix Sarah Medland. So Unix…  Long and venerable history  
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Andy Wang Object Oriented Programming in C++ COP 3330
The UNIX Shell Learning Objectives:
Some Linux Commands.
Linux command line basics III: piping commands for text processing
The Linux Operating System
Shell Script Assignment 1.
Shell Environments.
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Unix Talk #2 (sed).
Chapter Four UNIX File Processing.
Linux Shell Script Programming
Presentation transcript:

Shell Scripting Basics Arun Sethuraman

What’s a shell? Command line interpreter for Unix Bourne (sh), Bourne-again (bash), C shell (csh, tcsh), etc Handful of commands Text mining made easy!

Before we get started Unix/Mac Users: Open a terminal Windows Users: Should have installed VMware Player, and downloaded the virtual machine with Unix pre-loaded on it (else do it now!)

VMware Player Basics Allows creating/playing virtual machines We will use a standalone version of GNU/Linux called SliTaz, which is very minimalist (< 40 mb), but should work for all our exercises. Download all example files from my website: instead of from Blackboard. Save state of virtual machine, suspend, restart, etc. Switch environments using CTRL+ALT File sharing is a little complicated – so before you submit your assignment for next week, VMware users please me and stop by my office with your laptop to submit it (unless you can get Gmail to work without any glitches inside Midori).

Working at the prompt The ‘prompt’ refers to Unix’s native command line interface. Your prompt should look something like: Prompt commands are similar to python scripts – can specify variables, run one-liner commands, specify entire program flows, etc.

Unix 101 Try: man ls pwd clear Ctrl+C echo ps cat tail head cd mkdir rm cp mv cal kill vi/vim find set who

Piping Piping (|) refers to sequentially running multiple commands at one go. For eg. Say I want to read a file, then print only the last line of the file, try: cat example1.txt | tail –n 1 ls | grep “exam” cat example4.txt | head Important: Piped commands only work on the output of the previous command!

Regular Expressions Describe a pattern (sequence of characters) [A-Z]*, [a-z]* [0-9]*, [0-9]\{n\} Escape (special) characters – start with \ ^ - start of a line $ - end of a line

Examples Eg. {bicycle, bidirectional, biology, binary, bigotry, bill, big, bin, bionic, …} Eg. {Sunday, Monday, …, Saturday} Eg. {121, 123, 124, …, 129}

Examples TATAAA – TATA box, 25 bases upstream of transcription start site Telomeric repeat - (TTAGGG) n

Example 1 – grep Syntax: grep ‘pattern’ Create a new directory. Copy file “example1.txt” from /usr/home/shellbasics to your folder Explore contents of the file using cat/head/tail/vi Explore grep - copy first line of the file into another file (use –n flag) Copy 14 th line/last line/last 4 lines into another file Look for the word “Poe” in example1.txt, paste all instances into another file (name it ) Look for all numbers in the file – what’s wrong?

Example 2 – sed Syntax: sed ‘s/ / /g’ Stream Editor – substituting text Substitute all words that are “old” with “new” in example1.txt. Substitute all “a” with “A”, and all “b” with “B” in one line.

Example 3 – Your first shell script! Copy example3.sh to your folder. Explore its contents: #!/bin/sh sed ‘ s/a/A/g s/b/B/g ‘ example2.txt > example3.txt Execute this script using./example3.sh Oops – what happened here?

Permissions in Unix Unix has three permission/file access modes for all files – read (r), write (w), and execute (x). Need to specify permissions explicitly for executables. Try chmod +x example3.sh, then try./example3.sh

Example 3 – contd. Add script to change all small letters to capital letters in example2.txt and save it as a new file, example3.txt Execute it in the command line. Write a script to change find all numbers, and replace them with “[ref]”.

Example 4 – awk Syntax: awk ‘{ }’ Used to mine column formatted data. Columns denoted by $ Copy example4.txt to your folder awk to print only the third column of the file and save it to awk to print the 4 th and 5 th columns, separated by a tab character to a new file

Example 5 – a FASTA file Copy example5.fasta from /usr/home to your folder Explore its contents – what is the FASTA file format? What does it contain? Do you see a pattern? Now use any of the commands we just learned to extract only the gene-ID from the FASTA file. Print it. Count the number of “AC” repeats, save to a file Save only the first 5 lines in example5.fasta to

Example 6 – Executing commands in Shell What is BLAST? Write a shell script to: BLAST against all nucleotide BLAST databases. Save output of BLAST to a separate file – call it What hits do you get? Explore the BLAST output, pull out only gene ID’s for all your hits with ‘e’ value = 0.0, and with Genbank accessions (gb), save it to a new file HINT: You’ll notice that there are multiple ID’s, separated by “|” – to tell awk to use this as a delimiter, use awk ‘BEGIN { FS=“|”};…’ HINT: To sort a list, use “sort” function

Example 7 – Advanced scripts (Assignment) Write a python script to pull all gene ID’s from, look for these gene ID’s against NCBI and obtain all hits, save it to a file. Execute this python script, then parse out only protein id’s (gene/protein=) values from it using a shell script into a separate file. Copy all these protein ID’s (they should be Genbank accession ID’s), paste into the query at select all species on the list, add PANTHER-GO-Slim Biological Process to your columns.

Assignment (contd.) Save the output of PANTHER as a file. Now parse this file using grep/sed/awk to print only the GO terms – they should be separated by ; Make a unique list of these GO terms by using the ‘uniq’ function, save this to a final assignment submission file. HINT: Prior to pulling unique values, try replacing the “;” values with something else, say a newline character “\n”.