Chapter 10 Advanced File Processing. Regular Expressions A compact notation for representing patterns in strings Used by many common Linux utilities such.

Slides:



Advertisements
Similar presentations
UNIX Chapter 10 Advanced File Processing Mr. Mohammad Smirat.
Advertisements

Regular Expressions A simple and powerful way to match characters Laurent Falquet, EPFL March, 2005 Swiss Institute of Bioinformatics Swiss EMBnet node.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
Chin-Chih Chang CS 497C – Introduction to UNIX Lecture 28: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Quotes: single vs. double vs. grave accent % set day = date % echo day day % echo $day date % echo '$day' $day % echo "$day" date % echo `$day` Mon Jul.
Linux+ Guide to Linux Certification, Second Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
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.
UNIX. find command ● The find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
Filters using Regular Expressions grep: Searching a Pattern.
Review for Exam 1 Exam 1 on June 24 CSC 3320.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II CHAPTER 10: ADVANCED FILE PROCESSING.
Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers.
Va-scanCopyright 2002, Marchany Unit 6 – Solaris File Security Randy Marchany VA Tech Computing Center.
Agenda Sed Utility - Advanced –Using Script-files / Example Awk Utility - Advanced –Using Script-files –Math calculations / Operators / Functions –Floating.
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
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.
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Third Edition
1 Lecture 5 Additional useful commands COP 3353 Introduction to UNIX.
Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 6 Dr. Jerry Shiao, Silicon Valley University.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 10 Linux.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
BIF713 Additional Utilities. Linux Utilities  You have learned many Linux commands. Here are some more that you can use:  Data Manipulation (Reg Exps)
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
Regular Expression - Intro Patterns that define a set of strings (or, pieces of a string) Not wildcards (similar notion, but different thing) Used by utilities.
Pattern Matching CSCI N321 – System and Network Administration.
UNIX An Introduction. Brief History UNIX UNIX Created at Bell Labs, 1969 Created at Bell Labs, 1969 BSD during mid 70s BSD during mid 70s AT&T began offering.
Advanced Text Processing. 222 Lecture Overview  Character manipulation commands cut, paste, tr  Line manipulation commands sort, uniq, diff  Regular.
Unix Programming Environment Part 3-4 Regular Expression and Pattern Matching Prepared by Xu Zhenya( Draft – Xu Zhenya(
By Corey Stokes 9/14/10. What is grep? Global Regular Expression Print grep is a command line search utility in Unix Try: Search for a word in a.cpp file.
BASH – Text Processing Utilities Erick, Joan © Sekolah Tinggi Teknik Surabaya 1.
UNIX Commands RTFM: grep(1), egrep(1) & fgrep(1) Gilbert Detillieux April 13, 2010 MUUG Meeting.
What is grep ?  % man grep  DESCRIPTION  The grep utility searches text files for a pattern and prints all lines that contain that pattern. It uses.
Why UNIX? In the 1980s, UNIX became popular In the 1980s, UNIX became popular Customer demand for open systems: Customer demand for open systems: Application.
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.
Regular Expressions Copyright Doug Maxwell (
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
CSC 352– Unix Programming, Spring 2016
LINUX LANGUAGE MULTIPLE CHOICE QUESTION SET-5
Advanced File Processing
Looking for Patterns - Finding them with Regular Expressions
Regular Expression - Intro
PROGRAMMING THE BASH SHELL PART IV by İlker Korkmaz and Kaya Oğuz
Grep Allows you to filter text based upon several different regular expression variants Basic Extended Perl.
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Folks Carelli, Instructor Kutztown University
Tutorial of Unix Command & shell scriptS 5027
Unix Talk #2 grep/egrep/fgrep (maybe add more to this one….)
Lecture 5 Additional useful commands COP 3353 Introduction to UNIX 1.
Unix Talk #2 (sed).
Chapter 10 Advanced file processing
Chin-Chih Chang CS 497C – Introduction to UNIX Lecture 28: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
CSE 303 Concepts and Tools for Software Development
Regular Expressions and Grep
CSCI The UNIX System Regular Expressions
1.5 Regular Expressions (REs)
Software I: Utilities and Internals
Lecture 5 Additional useful commands COP 3353 Introduction to UNIX 1.
Presentation transcript:

Chapter 10 Advanced File Processing

Regular Expressions A compact notation for representing patterns in strings Used by many common Linux utilities such as: – less/more – ed – vi – emacs – egrep – grep – fgrep – awk – sed – lex – perl – python

Table 10.1 Regular Expression Operators

Table 10.1 More Regular Expression Operators

Regular Expression Examples cat|dog matches "cat" or "dog“..at matches any three-character string ending with "at", including "hat", "cat", and "bat". [hc]at matches "hat" and "cat". [^b]atmatches all strings matched by.at except "bat". ^[hc]at matches "hat" and "cat", but only at the beginning of the string or line. [hc]at$matches "hat" and "cat", but only at the end of the string or line.

Regular Expression Examples (0|1)+ 1+0* a*ba*ba* [A-Za-z][A-Za-z0-9]* (yaba|daba)+doo

Table 10.2 Examples of Regular Expressions for vi and Their Meaning

Table 10.3 Some Commonly Used vi Commands Illustrating the Use of Regular Expressions

File Compression compress uncompress gzip gunzip gzexe zcat zmore uuencode uudecode

Figure 10.1 The process of uuencoding and uudecoding

The Sort Utility Sorts lines of ASCII text Options for: – Ascending/descending order – Case folding – Ignoring leading whitespace – Alpha/numeric – Multiple keys

sort - sort lines of text files Syntax sort [OPTION]... [FILE]... Options -b, --ignore-leading-blanks ignore leading blanks -d, --dictionary-order consider only blanks and alphanumeric characters -f, --ignore-case fold lower case to upper case characters -i, --ignore-nonprinting consider only printable characters -n, --numeric-sort compare according to string numerical value -r, --reverse reverse the result of comparisons Other options: -k, --key=POS1[,POS2] start a key at POS1, end it at POS2 (origin 1) -t, --field-separator=SEP use SEP instead of non-blank to blank transition

Sort examples File donors.dat Bay Ching China Jack Arta Indonesia Cruella Lumper Malaysia sort donors.dat Bay Ching China Cruella Lumper Malaysia Jack Arta Indonesia

Sort Example – by last name sort +1 donors.dat Jack Arta Indonesia Bay Ching China Cruella Lumper Malaysia

Sort Example – by donation amount sort +2 donors.dat Jack Arta Indonesia Bay Ching China Cruella Lumper Malaysia sort +2 -n donors.dat Jack Arta Indonesia Bay Ching China Cruella Lumper Malaysia sort +2 -n -r donors.dat Cruella Lumper Malaysia Bay Ching China Jack Arta Indonesia

Locating Files find whereis which

Find command Syntax Find directory-list expression Searches directory-list for files that match conditions in expression Can find files by name, owner, permission, size, age, links

Find Command Examples find ~ -name *.gif -print find / -name socket.h -print find / -size c -print find ~ -newer filetocompare

Searching File Contents grep egrep fgrep

Grep – Get Regular Expression & Print Syntax grep [options] pattern [file-list] Searches files in file-list, prints lines which match the given pattern Options to fold case, print line #’s, filenames, non- matching lines fgrep – faster but dumb egrep – slower but more powerful

Command History A list of the recently used commands is maintained and controlled by the variables: – HISTSIZE – HISTFILE – HISTFILESIZE

Table 10.4 Commonly Used Event Designators for History Expansion

Table 10.5 Commonly Used Event Designators for History Expansion

Table 10.6 Commonly Used Modifiers for History Expansion