Presentation is loading. Please wait.

Presentation is loading. Please wait.

©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.

Similar presentations


Presentation on theme: "©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."— Presentation transcript:

1 ©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

2 ©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

3 ©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? a. @ 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

4 ©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.

5 ©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

6 ©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

7 ©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.

8 ©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.

9 ©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

10 ©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.

11 ©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 

12 ©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.

13 ©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

14 ©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]

15 ©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

16 ©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

17 ©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

18 ©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 (172.17.55.167) Enables you to perform case-conversion

19 ©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

20 ©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:

21 ©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.

22 ©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"

23 ©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.

24 ©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.

25 ©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.

26 ©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.

27 ©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.

28 ©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).


Download ppt "©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."

Similar presentations


Ads by Google