©NIIT Pipes and Filters Lesson 2B / Slide 1 of 28 Introduction to Linux Pre-Assessment Questions 1.Consider the following statements: Statement A: A text.

Slides:



Advertisements
Similar presentations
Pre-Assessment Questions
Advertisements

UNIX Chapter 12 Redirection and Piping Mr. Mohammad Smirat.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
Linux+ Guide to Linux Certification, Second Edition
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Linux+ Guide to Linux Certification, Second Edition
BIF703 Redirection Continued: Pipes. Redirection Recall from the previous slides we defined stdin, stdout, and stderr and we learned how to redirect these.
Guide To UNIX Using Linux Third Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
This slide deck is for LPI Academy instructors to use for lectures for LPI Academy courses. ©Copyright Network Development Group Module 8 Pipes,
CSCI 330 T HE UNIX S YSTEM File operations. OPERATIONS ON REGULAR FILES 2 CSCI The UNIX System Create Edit Display Contents Display Contents Print.
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.
Chapter 4: UNIX File Processing Input and Output.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II CHAPTER 10: ADVANCED FILE PROCESSING.
Advanced File Processing
Ch 51 Internal Commands COPY and TYPE. Ch 52 Overview Will review file-naming rules.
Introduction to Shell Script Programming
Lesson 11-Locating, Printing, and Archiving User Files.
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.
Guide To UNIX Using Linux Fourth Edition
A Guide to Unix Using Linux Fourth Edition
Unix programming Term: III B.Tech II semester Unit-II PPT Slides Text Books: (1)unix the ultimate guide by Sumitabha Das (2)Advanced programming.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Jozef Goetz, expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert.
Linux+ Guide to Linux Certification, Third Edition
©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
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.
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
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.
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Chapter Four I/O Redirection1 System Programming Shell Operators.
Ch 91 Pipes, Filters and Redirection. Ch 92 Overview Will use redirection to redirect standard input and standard output.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Chapter Three The UNIX Editors.
Chapter Six Introduction to Shell Script Programming.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Command Prompt Chapter 9 Pipes, Filters, and Redirection ©Richard Goldman 11/30/2000 Revised 10/16/2001.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Second Edition
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
In the last class, Filters and delimiters The sample database pr command head and tail commands cut and paste commands.
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.
SIMPLE FILTERS. CONTENTS Filters – definition To format text – pr Pick lines from the beginning – head Pick lines from the end – tail Extract characters.
Chapter 14: Sequential Access Files
Lesson 5-Exploring Utilities
Guide To UNIX Using Linux Third Edition
INTRODUCTION TO UNIX: The Shell Command Interface
Guide To UNIX Using Linux Third Edition
Chapter Four UNIX File Processing.
Data Groupings: File File: a group of related records
Presentation transcript:

©NIIT Pipes and Filters Lesson 2B / Slide 1 of 28 Introduction to Linux Pre-Assessment Questions 1.Consider the following statements: Statement A: A text editor can be used to create a new file. Statement B: A text editor can be used for searching text in an existing file. Which of the following is correct with respect to the above statements? a.Statement A is True and Statement B is False b.Statement A is False and Statement B is True c.Both, Statement A and Statement B, are True d.Both, Statement A and Statement B, are False

©NIIT Pipes and Filters Lesson 2B / Slide 2 of 28 Introduction to Linux Pre-Assessment Questions (Contd.) 2.Consider the following statements: Statement A: In vi editor, the d command is used to scroll down half a page at a time. Statement B: In vi editor, the F command is used to scroll down two pages at a time. Which of the following is correct with respect to the above statements? a.Statement A is True and Statement B is False b.Statement A is False and Statement B is True c.Both, Statement A and Statement B, are True d.Both, Statement A and Statement B, are False

©NIIT Pipes and Filters Lesson 2B / Slide 3 of 28 Introduction to Linux Pre-Assessment Questions (Contd.) 3.Alice is a novice for the emacs editor. She wants to delete the current line in a file. Which of the following commands should she use? b. k c. y d. d 4.Jane is working on the vi editor. Which of the following command sequence should she follow to copy first 3 lines above the line number 10? a.Keep the cursor at first line, press yy, keep the cursor at the line number 10, press p b.Keep the cursor at first line, press 3yy, keep the cursor at the line number 10, press p c.Keep the cursor at first line, press 3yy, keep the cursor at the line number 10, press P d.Keep the cursor at first line, press 3yy, keep the cursor at the line number 10, press O

©NIIT Pipes and Filters Lesson 2B / Slide 4 of 28 Introduction to Linux Pre-Assessment Questions (Contd.) 5.While writing a C++ program in vi editor, Smith needs to append a keyword at the end of a line. Which key combination should he use? a. When the cursor is on the target line, press i. b. When the cursor is on the target line, press O. c. When the cursor is on the target line, press o. d. When the cursor is on the target line, press A.

©NIIT Pipes and Filters Lesson 2B / Slide 5 of 28 Introduction to Linux Solutions to Pre-Assessment Questions 1.c. Both, Statement A and Statement B, are True 2.a. Statement A is True and Statement B is False 3.b. k 4.c. Keep the cursor at first line, press 3yy, keep the cursor at the line number 10, press P 5.d. When the cursor is on the target line, press A

©NIIT Pipes and Filters Lesson 2B / Slide 6 of 28 Introduction to Linux Objectives In this lesson, you will learn to: Identify standard input, output, and error files Give input to a command from a file Redirect output of a command or the error to a disk file Use grep, wc, cut, tr, and sort filters Use pipes to combine commands and filters Use tee command to display output on the standard output and store it in a file

©NIIT Pipes and Filters Lesson 2B / Slide 7 of 28 Introduction to Linux Standard Files A computer system consists of mainly three parts: The input devices, such as keyboard and mouse, are used to accept data from the user. The output devices, such as monitor and printer, are used to display/print information or any error messages that might occur. The processing device, such as CPU, processes the user input according to the specified instructions, to generate the desired output.

©NIIT Pipes and Filters Lesson 2B / Slide 8 of 28 Introduction to Linux Standard Files (Contd.) Standard input file accepts the input from the user for various commands that need input from the user. The keyboard is default source of input and is referred to as the standard input file. Standard output file displays the output of a command to the user. The monitor is default destination of output and is referred to as the standard output file. Standard error file displays the error messages which are generated during a command execution. The error messages are displayed on the monitor by default and therefore monitor acts as standard error file.

©NIIT Pipes and Filters Lesson 2B / Slide 9 of 28 Introduction to Linux Redirection Redirection: Changes the assignments for the standard input, standard output, and the standard error Enables you to take input to a command from a file other than the keyboard Enables you to write the output of a command or the error to a disk file or printed, instead of the monitor Is of the following three types: Input redirection Output redirection Error redirection

©NIIT Pipes and Filters Lesson 2B / Slide 10 of 28 Introduction to Linux Input Redirection The following example illustrates the usage of input redirection: $ cat < test1  The less than symbol, <, implies input redirection from the file, test1. The above command can also be written using the file descriptor as: $ cat 0< test1  In the preceding code, 0 indicates input redirection.

©NIIT Pipes and Filters Lesson 2B / Slide 11 of 28 Introduction to Linux Output Redirection The following example illustrates the usage of output redirection: $ cat test1 > out_test  The greater than symbol, >, implies redirection of output to the file, out_test. In output redirection, the file to which the output is redirected is first created on the disk as an empty file and then the output is sent to this file. If the file already exists, its content is deleted before the output is written to it. If you want to append the output to the file, out_test, the command is: $ cat test1 >> out_test  The previous commands can also be written using the file descriptor as: $ cat test1 1> out_test  $ cat test1 1>>out_test 

©NIIT Pipes and Filters Lesson 2B / Slide 12 of 28 Introduction to Linux Error Redirection Error redirection first creates the file to which the error messages are redirected and then writes the error output to the file. The following example illustrates the usage of error redirection: $ cat test_2 2> error-mesg  In the preceding command, the file, test_2, does not exist in the current directory. When a user tries to execute the preceding command, Linux will generate an error message because the execution is unsuccessful. This message, which would otherwise be displayed on the monitor (the standard error file), is written to the file, error ‑ mesg.

©NIIT Pipes and Filters Lesson 2B / Slide 13 of 28 Introduction to Linux Filters A filter is a program that takes its input from the standard input file, processes (or filters) it, and sends its output to the standard output file. Some examples of filters are: grep cat wc tr cut

©NIIT Pipes and Filters Lesson 2B / Slide 14 of 28 Introduction to Linux The grep Filter The grep filter: Stands for Global Regular Expression Print. Searches a file for a particular pattern of characters, and displays all lines that contain that pattern. The pattern that is searched in the file is referred to as the regular expression. Cannot be used without specifying a regular expression. Has the following syntax: grep [options] pattern [filename]

©NIIT Pipes and Filters Lesson 2B / Slide 15 of 28 Introduction to Linux Specifying Regular Expressions Regular expressions can be used to specify simple patterns of characters to highly complex ones. The following table lists some simple patterns: You can also specify complex regular expressions, such as, [], [] with hyphen, ^, ^ within [], $,. (dot), and \ (backslash). RegularExpression Pattern ‘A’The character A ‘F’The character F ‘New'The word New

©NIIT Pipes and Filters Lesson 2B / Slide 16 of 28 Introduction to Linux The wc Filter The wc filter: Is used to count the number of lines, words, and characters in a disk file or in the standard input Has the following syntax: wc [option] [filename] The following table lists the options of the wc filter: OptionFunction –lDisplays the number of lines –wDisplays the number of words –cDisplays the number of characters

©NIIT Pipes and Filters Lesson 2B / Slide 17 of 28 Introduction to Linux The cut Filter The cut filter: Is useful when specific columns from the output of certain commands (such as ls, who ) need to be extracted Has the following syntax: cut [options] [filename] The following table lists the options of the cut filter: OptionFunction -f Displays the specified columns -c Displays the specified characters -d Specifies the column delimiter

©NIIT Pipes and Filters Lesson 2B / Slide 18 of 28 Introduction to Linux The tr Filter The tr filter: Can be used to translate one set of characters to another Can also be used to squeeze repeated occurrences of a character into one Uses the -s option to squeeze several occurrences of a character into one character. For example, who > temporary  $ tr -s " " < temporary  root tty1 Sep 28 17:02 steve pts/4 Sep 28 19:36 ( ) Enables you to perform case-conversion

©NIIT Pipes and Filters Lesson 2B / Slide 19 of 28 Introduction to Linux The sort Filter The sort filter arranges each line of the standard input in ascending order. The following table lists the options of the sort filter: OptionFunction -rSorts the input in reverse order -fArranges the input to the sort filter consisting of digits, alphabets, and other characters in the ASCII sequence -nArranges the numbers also in ASCII sequence Sorts the content of the specified file +pos1 – pos2 Sorts a file in the order of a specific column -tCreates a file with a different column separator -oSaves the output of the sort filter to a disk file

©NIIT Pipes and Filters Lesson 2B / Slide 20 of 28 Introduction to Linux Pipes Pipes enable you to combine multiple commands and execute them as a single command. For example, $ ls | more  Pipes are represented using the vertical bar (|), which indicates to the shell that the output of the command before the ‘|’ is to be sent as input to the command after the ‘|’. The following figure shows the working of a pipe:

©NIIT Pipes and Filters Lesson 2B / Slide 21 of 28 Introduction to Linux The tee Command The tee command: Pipes the standard output of a command to another command, and also save it on disk for later use or displays on the standard output Creates the file if the file where data is to be written does not exist Overwrites the content of the files if the file already exists An example of the tee command is: $ cat temp | tee temp1 temp2  The – a (append) option can be used to append the new content to an existing file.

©NIIT Pipes and Filters Lesson 2B / Slide 22 of 28 Introduction to Linux Demonstration-Sorting and Redirecting Output Problem Statement The details of various customers who have made calls to Deez Telecommunications are stored in the file, Customer. Sample data from the file is as follows: "10:30","000004","Angela","Smith","16223 Radiance Court","Kansas City","Kansas" "10:36","000002","Barbara","Johnson","227 Beach Ave.","Alexandria","Virginia" "10:48","000003","Betty","Williams","1 Tread Road","Dublin","Georgia" "11:15","000001","Carol","Jones","765 Furling Rd Apt","Norton","Kansas" "11:23","000005","Catherine","Roberts","5508 Aquiline Court","Norton","Kansas" "11:44","000038","Joyce","Phillips","535 Darwin Avenue ","Columbus","Georgia" "12:20","000026","Linda","Lewis","1524 Patagonia Lane ","Columbus","Georgia" "14:00","000022","Ruth","Green","459 Ridge Road ","Middle Town","New Jersy"

©NIIT Pipes and Filters Lesson 2B / Slide 23 of 28 Introduction to Linux Demonstration-Sorting and Redirecting Output (Contd.) Problem Statement (Contd.) In the file, the field delimiter is ', '. The various fields are CustomerCode, FirstName, LastName, Address, City, and State. Angela has been assigned the task to sort the file and display only the CustomerCode, FirstName and LastName of the customers living in Georgia. The output should be displayed in the order of the CustomerCode.

©NIIT Pipes and Filters Lesson 2B / Slide 24 of 28 Introduction to Linux Demonstration-Sorting and Redirecting Output (Contd.) Solution To sort the file and redirect the output as required in the problem statement, Angela needs to perform the following tasks: 1.Identify the commands to be used. 2.Execute the identified command in the correct sequence. 3.Verify whether or not the command has displayed the required information.

©NIIT Pipes and Filters Lesson 2B / Slide 25 of 28 Introduction to Linux Demonstration-Exporting Content of a File Problem Statement Export the content of the file Customer_Details present in the ~/CustomerCalls directory into a file, New_Details. The exported data needs to be in uppercase. You also need to view the data in the new format on the screen, one screen-full at a time.

©NIIT Pipes and Filters Lesson 2B / Slide 26 of 28 Introduction to Linux Demonstration-Exporting Content of a File (Contd.) Solution To export the data of Customer_Details file to a database, you need to do the following tasks: 1.Identify the commands to be used. 2.Execute the identified command in the correct sequence. 3.Verify whether or not the command has displayed the required information.

©NIIT Pipes and Filters Lesson 2B / Slide 27 of 28 Introduction to Linux Summary In this lesson, you learned: In Linux, the keyboard is referred to as the standard input file and the monitor is referred to as the standard output and the standard error file. The input, output, and errors can be redirected to a file other than the standard files using the file descriptors along with the redirection symbols, > and <. The output and error(s) can be redirected, in the append mode, to add the redirected output or error to an existing file using the >> symbol. A filter is a command or a user program that takes input from the standard input file, processes the data and gives output on the standard output file. Examples of filters are: grep, wc, tr, and cut. The grep filter searches the standard input or a file for a particular pattern of characters, and displays all lines that contain that pattern. The wc filter counts the number of lines, words, and characters in a disk file or in the standard input.

©NIIT Pipes and Filters Lesson 2B / Slide 28 of 28 Introduction to Linux Summary (Contd.) The cut filter is used when specific columns from the output of certain commands (or files) need to be extracted. The tr filter is used to translate one set of characters to another. The sort filter arranges each line of the standard input or a file in a particular order. A pipe is a feature through which the standard output of a command or user program can be sent as the standard input to another command or user program. The tee command takes standard input and writes to standard output and to file(s).