CSC 2500: Unix Lab Fall 2016

Similar documents
CSC 2500: Unix Lab Fall 2016

CSC 2500: Unix Lab Fall 2016

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Review of Fundamentals

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

Perl and R Scripting for Biologists

6 Redirection. Standard Input, Output, And Error. 6 Redirection

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Linux Tutorial #4. Redirection. Output redirection ( > )

Introduction to UNIX command-line

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Introduction to the shell Part II

Lab 2: Linux/Unix shell

COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page and visit the COL100 course page.

Advanced Linux Commands & Shell Scripting

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction to Linux

Introduction: What is Unix?

Working With Unix. Scott A. Handley* September 15, *Adapted from UNIX introduction material created by Dr. Julian Catchen

Introduction To. Barry Grant

Recap From Last Time:

BGGN 213 Working with UNIX Barry Grant

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

5/20/2007. Touring Essential Programs

CSCI 2132 Software Development. Lecture 4: Files and Directories

EECS2301. Lab 1 Winter 2016

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

Laboratory 1 Semester 1 11/12

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

Command-line interpreters

Introduction to UNIX. SURF Research Boot Camp April Jeroen Engelberts Consultant Supercomputing

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

find starting-directory -name filename -user username

ITST Searching, Extracting & Archiving Data

Reading and manipulating files

System Administration

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

THE LINU X T H E L IN U X COMM A ND L INE

CSC UNIX System, Spring 2015

Shells and Shell Programming

Creating a Shell or Command Interperter Program CSCI411 Lab

The Unix Shell. Pipes and Filters

A Brief Introduction to the Linux Shell for Data Science

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

Practical 02. Bash & shell scripting

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Useful Unix Commands Cheat Sheet

Introduction to Linux

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

Open up a terminal, make sure you are in your home directory, and run the command.

Basics. I think that the later is better.

Unix Shell. Advanced Shell Tricks

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

The Unix Shell & Shell Scripts

Files and Directories

Assignment 1: Communicating with Programs

Computer Systems and Architecture

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

Scripting Languages Course 1. Diana Trandabăț

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

Chapter 9. Shell and Kernel

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

UNIX Essentials Featuring Solaris 10 Op System

Recap From Last Time: Setup Checklist BGGN 213. Todays Menu. Introduction to UNIX.

Shells and Shell Programming

EECS2031 Winter Software Tools. Assignment 1 (15%): Shell Programming

CS356: Discussion #1 Development Environment. Marco Paolieri

UNIX Kernel. UNIX History

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Computer Systems and Architecture

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

CSCI 2132 Software Development. Lecture 5: File Permissions

PROGRAMMING PROJECT ONE DEVELOPING A SHELL

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi and Cyrill Stachniss

CSCI 4061: Pipes and FIFOs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Week 5 Lesson 5 02/28/18

Module 8 Pipes, Redirection and REGEX

Version Control with Git

Lab #2 Physics 91SI Spring 2013

IB047. Unix Text Tools. Pavel Rychlý Mar 3.

Linux for Beginners. Windows users should download putty or bitvise:

The input can also be taken from a file and similarly the output can be redirected to another file.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Introduction to UNIX command-line II

Cloud Computing and Unix: An Introduction. Dr. Sophie Shaw University of Aberdeen, UK

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Transcription:

CSC 2500: Unix Lab Fall 2016 IO Redirection Mohammad Ashiqur Rahman Department of Computer Science College of Engineering Tennessee Tech University

Agenda Standard IO IO Redirection Pipe Various File Processing Unix Commands Lab 3: Learning IO Redirection M. Ashiq Rahman, Tennessee Tech University 2

What is IO Redirection? With the IO redirection one can: Redirect the input and output of commands to and from files Connect multiple commands together into powerful command pipelines M. Ashiq Rahman, Tennessee Tech University 3

Standard IO Programs typically produce: Useful results or data Status or error messages Everything is a file, so the output is sent to one of two files Standard Output (results) (1) Standard Error (errors or status) (2) Input comes from one file Standard Input (0) M. Ashiq Rahman, Tennessee Tech University 4

File and Pipe Redirection The > redirects stdout to a file The left hand side is the command/program that writes to stdout The file with the provided name may exist If not, it is created If it does exist, it is truncated Examples: ls -l > list.txt files.txt will contain a long listing of the current directory wc -l file.txt > num_lines.dat num_lines.dat will have a single number, i.e. the number of lines in file.txt M. Ashiq Rahman, Tennessee Tech University 5

File and Pipe Redirection (2) The >> also redirects stdout to a file, but The file with the provided name may exist If not, it is created If it does exist, it is appended Examples: $ wc backup.tcl > counts.dat $ cat counts.dat 68 240 1600 backup.tcl $ wc install.sh >> counts.dat $ cat counts.dat 68 240 1600 backup.tcl 66 227 1608 install.sh M. Ashiq Rahman, Tennessee Tech University 6

Redirecting Standard Input The < redirects from stdin The file must exist and can be opened for reading The program reads the data from the file just as if it were typed in at the keyboard Example: $ cat names.txt Joe Mary Ken Steve Annie $ sort < names.txt > sorted_names.txt $ cat sorted_names.txt Annie Joe Ken Mary Steve M. Ashiq Rahman, Tennessee Tech University 7

Redirecting Standard Error One can redirect stderr using 2> For example, to save your compiler output: $ g++ -Wall -o sortit sortit.cpp 2> error.txt $ tail error.txt sortit.cpp:32:16: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for (int a : s) { ^ sortit.cpp:38:35: error: expected expression std::sort(s.begin(), s.end(), [](int a, int b) { ^ sortit.cpp:41:16: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for (int a : s) { ^ 6 warnings and 1 error generated. M. Ashiq Rahman, Tennessee Tech University 8

Redirecting stdout and stderr to One File There are cases in which one may wish to capture all of the output of a command to a single file. Redirect both standard output and standard error at the same time $ ls -l /bin/usr &> ls-output.txt M. Ashiq Rahman, Tennessee Tech University 9

Pipes The UNIX system allows stdout of a command to be connected to stdin of another command. Using the pipe character The above command is written like so: ps -ef grep login less What does it do? Lists all processes that have the word login in their command line one page at a time M. Ashiq Rahman, Tennessee Tech University 10

The Difference Between > and The redirection operator connects a command with a file While the pipeline operator connects the output of one command with the input of a second command The following is not possible: command1 > command2 M. Ashiq Rahman, Tennessee Tech University 11

Filters Pipelines are often used to perform complex operations on data Pipelines used in this way are called filters Example: uniq -- report or filter out repeated lines in a file wc -- word, line, character, and byte count $ ls /bin /usr/bin sort uniq wc -l What does it will do? M. Ashiq Rahman, Tennessee Tech University 12

Lab 03 Objective: Executing Unix commands with options and arguments Getting rid of output going to stderr Pipes The use of XQuery Lab Prerequisites: Your system should have the following commands installed: (1) 7z, (2) xqilla, (3) sort, (4) wget, and (5) split M. Ashiq Rahman, Tennessee Tech University 13

Lab 03: Problem Description You will be provided a file that I downloaded from the Internet. The file contains a database, structured as XML, of proteins. Unfortunately, I do not want the file in XML format because it is too hard to read. Furthermore, I am only interested in two fields from the file. Those fields are the id field and the description field. The file is sorted by id, but I want the file sorted by description. I do not want to have to deal with the data as one big because loading this file into text editors is problematic. So, I want the data divided into smaller, more manageable, files. M. Ashiq Rahman, Tennessee Tech University 14

Lab 03: Homework Write a shell script called that does all of the above. All the works need to be accomplished in two lines. The entire shell script is going to be 3 lines long. The first line will be the obligatory #!/bin/bash The following 2 lines will download the compressed XML file and generate the manageable files. Your script file should have the following name: Protein_Info_<First Name><Last Name>.sh. Submission Deadline: Friday, September 16, 2016 Submission Site: ilearn (a Dropbox folder named Homework 03 ) Submission Content: Submit the script file. M. Ashiq Rahman, Tennessee Tech University 15

Lab Practice Download the XML file from the link below and show the downloaded file: http://users.csc.tntech.edu/~marahman/courses/csc_2500/largefile.txt Split the downloaded file into multiple smaller files (using default, the number of lines, and the number of bytes options). Merge (using cat) of two small files (split based on bytes) and print the number of lines/words in the merged result using pipe and wc. To install xqilla and p7zip (7z) sudo apt-get update sudo apt-get install xqilla p7zip p7zip-full M. Ashiq Rahman, Tennessee Tech University 16

THANKS Acknowledgement: - Dr. Mike Rogers - Linux man pages M. Ashiq Rahman, Tennessee Tech University 17