Lesson 6-Using Utilities to Accomplish Complex Tasks.

Slides:



Advertisements
Similar presentations
A Guide to Unix Using Linux Fourth Edition
Advertisements

Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Linux+ Guide to Linux Certification, Second Edition
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Guide To UNIX Using Linux Third Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Grep, comm, and uniq. The grep Command The grep command allows a user to search for specific text inside a file. The grep command will find all occurrences.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
Linux Commands LINUX COMMANDS.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Advanced File Processing
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
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.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Introduction to Shell Script Programming
Lesson 11-Locating, Printing, and Archiving User Files.
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.
Guide To UNIX Using Linux Fourth Edition
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
LIN Unix Lecture 3 Hana Filip. LIN UNIX Resources UNIX Tutorials UNIX help for.
Agenda Chapter 1: Linux (Unix) Features Commands (Chapters 2 & 3) Command Structure / Command line editing man, passwd, cal, date, whereis, which Working.
Linux+ Guide to Linux Certification, Second Edition
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Scripting Languages Course 2 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
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.
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Introduction to Unix (CA263) File Processing (continued) By Tariq Ibn Aziz.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Learning basic Unix command It 325 operating system.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
Familiarizing with UNIX Commands. UNIX Commands Unix systems are heavily command based. This often makes us feel uncomfortable. Moreover the system is.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Linux Administration Working with the BASH Shell.
Filters and Utilities. Notes: This is a simple overview of the filtering capability Some of these commands are very powerful ▫Only showing some of the.
UNIX Basics Matt Hayward October 18, 2016 LS560 – Information Technology for information professionals.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Quality Thought Technologies
Prepared by: Eng. Maryam Adel Abdel-Hady
Some Linux Commands.
Chapter 6 Filters.
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Chapter Four UNIX File Processing.
Linux Commands LINUX COMMANDS.
Presentation transcript:

Lesson 6-Using Utilities to Accomplish Complex Tasks

Overview Creating and executing a script to list user information. Listing directories and files separately. Identifying changes made to files in a directory. Creating a complex script.

Creating and Executing a Script to List User Information Creating a script. Executing a script.

Creating a Script A series of commands can be executed repeatedly/automatically by placing them in a script file. Placing commands in scripts helps avoid errors and save time. The vi editor can be used to create a file. The ":wq" commands are used to write to a file and return to the shell.

Executing a Script The commands in a file can be executed in two ways: Instructions can be given to the current shell to read the file (source) and execute all the commands. The script file can be made executable, and a child shell can be started to read the script file and execute the commands.

Executing a Script The command used to make the shell executable is “chmod +x filename”. By default, the output of the script is redirected to the screen. The output of the script can be redirected to a file.

Listing Directories and Files Separately Selecting only directories / files: The “ls –F | grep /” command is used to select only lines that contain directory names. The “ls –F | grep / | column” command can be used to put the output into columns. The “ls –F | grep –v / | column” command is used to select only files.

Listing Directories and Files Separately Selecting Directories Using Multiple Utilities

Listing Directories and Files Separately Interpretation by grep Using –v option

Listing Directories and Files Separately Adding comments to scripts: The # (pound) sign is used to add comments to scripts. Ensure that the # sign is placed at the beginning of each line. The pound (#) sign cannot be used inside a long command line.

Identifying Changes Made to Files in a Directory Collecting data about files in a directory: The “ls –l directory name” command can be used to provide information about the files in a particular directory. The output of the code can also be redirected to another file by the command "ls -l directoryname > filename”. The information includes the current status of each file, such as permissions, date of modification, owner, etc.

Identifying Changes Made to Files in a Directory Comparing file information: The “comm” command is used to identify the common aspects between two files. It requires two arguments – the names of the two the files that are to be compared. The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines in common.

Identifying Changes Made to Files in a Directory Comparing file information: The “diff” command is used to identify the differences between two files. It requires two arguments – the names of the two files to be compared. The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines common to the two files.

Creating a Complex Script Determining the number of unique words in a file. Removing punctuation. Converting characters to lowercase. Putting each word on a line. Removing blank lines. Sorting the lines.

Determining the Number of Unique Words in a File The “uniq” utility is used to: Provide a list of unique words in a file. The number of times that each word is used. The number of unique words.

Determining the Number of Unique Words in a File The uniq utility outputs both, unique lines as well as single copies of any lines that are duplicate and adjacent. The utility deletes identical lines. The uniq utility deletes only those lines that are identical and adjacent.

Determining the Number of Unique Words in a File The following things must be ensured for the uniq utility to work properly: Punctuation and blank lines must be removed. Differences in case for the same word must be reconciled. The words must be one word to a line in a sorted order.

Removing Punctuation Shell and Utility Interpretation

Converting Characters to Lowercase Shell and tr Interpretation

Putting Each Word on a Line To remove duplicate words using the uniq utility, the data must be modified to ensure that each word is on a line by itself. The new line character “\n” is used to separate lines in a file. The ASCII character code 012 can also be used to separate lines in a file.

Putting Each Word on a Line The “man ascii” command is used to examine the ASCII characters and their associated codes. TAB characters can also be replaced with new line characters.

Putting Each Word on a Line Using tr Utility to Replace Characters

Removing Blank Lines A View from the Shell

Sorting the Lines The “sort” command can be used to sort the output such that all lines containing the same word are on adjacent lines. The “uniq –c” command can be used to remove all duplicate lines. The “sort –rn” command can be used to list the most frequently used words first.

Summary A series of commands placed in a script file can be repeatedly executed, avoiding errors and saving time. The ls utility provides a list of all the files and subdirectories in the current directory. The # sign is used to add comments to script files. The pipeline feature of UNIX is very useful and is central to manipulating data effectively with UNIX utilities.