LPI 2010 NLLGG Trainer: Jeroen van Pelt Bijeenkomst 4:Werken met tekstbestanden 27.3.2010.

Slides:



Advertisements
Similar presentations
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Advertisements

EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
A Guide to Unix Using Linux Fourth Edition
 *, ? And [ …] . Any single character  ^ beginning of a line  $ end of the line.
Linux+ Guide to Linux Certification, Second Edition
CS 497C – Introduction to UNIX Lecture 25: - Simple Filters Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 23: - Simple Filters Chin-Chih Chang
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.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Introduction to UNIX GPS Processing and Analysis with GAMIT/GLOBK/TRACK T. Herring, R. King. M. Floyd – MIT UNAVCO, Boulder - July 8-12, 2013 Directory.
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 Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
CS 124/LINGUIST 180 From Languages to Information Unix for Poets (in 2014) Dan Jurafsky (From Chris Manning’s modification of Ken Church’s presentation)
Shell Script Examples.
Review for Exam 1 Exam 1 on June 24 CSC 3320.
Chapter 4: UNIX File Processing Input and Output.
Advanced File Processing
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
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.
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.
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.
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 8 Shell.
Dedan Githae, BecA-ILRI Hub Introduction to Linux / UNIX OS MARI eBioKit Workshop; Nov , 2014.
Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Third Edition
Regular expressions Used by several different UNIX commands, including ed, sed, awk, grep A period ‘.’ matches any single characters.X. matches any X.
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
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.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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.
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.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Chapter 9 Basic File Processing. Displaying File Contents cat, cat w/append tac nl pr more less head tail.
Introduction to Unix (CA263) File Processing (continued) By Tariq Ibn Aziz.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Chapter Four I/O Redirection1 System Programming Shell Operators.
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
CSC 352– Unix Programming, Spring 2015 February 2015 Unix Filters.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
In the last class, Filters and delimiters The sample database pr command head and tail commands cut and paste commands.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
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.
LPI 2010 NLLGG Trainer: Jeroen van Pelt Bijeenkomst 7: Package management/Software installeren
LPI 2010 NLLGG Trainer: Jeroen van Pelt Bijeenkomst 3: Systeem opstarten en werken met filesystemen
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Chapter 6 Filters.
Linux command line basics III: piping commands for text processing
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
The Linux Command Line Chapter 6
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Unix Talk #2 (sed).
Chapter Four UNIX File Processing.
Exploring Shell Commands, Streams, and Redirection
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
LPI Linux Certification
Presentation transcript:

LPI 2010 NLLGG Trainer: Jeroen van Pelt Bijeenkomst 4:Werken met tekstbestanden

 Terugblik bijeenkomst 3  Tekstbestanden verwerken met filters  Process text streams using filters  Tekstbestanden doorzoeken met regular expressions  Search text files using regular expressions  Het basis gebruik van vi  Perform basic file editing operations using vi  Afronding en huiswerk Agenda

 Candidates should should be able to apply filters to text streams.  Key Knowledge Areas  Send text files and output streams through text utility filters to modify the output using standard UNIX commands found in the GNU textutils package.  Boek: LPI Process text streams using filters

  Tools om tekstbestanden en streams te filteren GNU textutils-1

 cat, tac - Concatenate files and print on the standard output, from beginning to end or end to beginning, respectively.  head, tail - Output the first and last part of files.  nl - Number lines of files.  wc - Print the number of lines, words, and bytes (in that order) in files.  cut - Remove sections from each line of files.  tr - Translate or delete character.  expand, unexpand - Convert tabs to spaces and space to tabs. GNU textutils-2

 paste - Merge lines of files.  join - Join lines of two files on a common field.  uniq - Remove duplicate lines from a sorted file.  split - Split a file into pieces.  fmt - Simple optimal text formatter.  pr - Convert text files for printing.  sort - Sort lines of text files.  od - Dump files in octal and other formats. GNU textutils-3

 cat [options] [files...]  tac [options] [files...]  Options:  -n: number all output lines.  Examples:  cat file # Display file to the standard output  cat chapter* # Display all chapters to standard output GNU textutils voorbeelden Bestanden samenvoegen

 head [options] [files...]  tail [options] [files...]  Options:  -n: number of lines to be displayed. (head and tail)  -c: number of bytes to be displayed (head and tail)  -f: append output. (tail)  -s #: iteration for new data every # sec. (tail) GNU textutils voorbeelden Einde/begin bestand bekijken

 Examples:  head file # Display the first 10 lines of file.  head -n 2 file # Display the first 2 lines of file.  tail -c 10 file # Display the last 10 bytes of file.  tail -f -s 1 /var/log/messages

 nl [options] [files...]  Options:  -i #: increment line number by #.  -b: numbering style:  a: number all lines  t: non-empty lines  n: number no lines  -n: numbering format:  rz: right justified  ln: left justified. GNU textutils voorbeelden Regels nummeren

 Examples:  nl file # Add the line number in each line in # the file.  nl -b t -n rz file # Add the line number to each # non-empty line with zero-completed # format.

 wc [options] [files...]  Options: -c: print the size in bytes. -m: print the number of characters. -w: print the number of words. -l: print the number of lines. -L: print the length of the longest line. GNU textutils voorbeelden Items in een bestand tellen

 Examples:  wc *.[ch] # Display the number of lines, words, # and characters for all files.c or.h.  wc -L file # Display the size of the longest line.  wc -w file # Display the number of words.

 cut [options] [files...]  Options:  -b #: Extract the byte at position #.  -f #: Extract the field number #. GNU textutils voorbeelden Cutting fields in files

 Examples:  cut -b 4 file # Extract and display the 4th # byte of each line of file.  cut -b 4,7 file # Extract and display the 4th # and 7th byte of each line.  cut -b -2,4-6, 20- file # Extract characters leading # up to 2 (1 and 2), 4 to 6, and # 20 to the end of the line for # each line of file.  cut -f 1,3 -d: /etc/passwd # Extract the username and ID of # each line in /etc/passwd.

 tr [options] SET1 SET2  Options:  -d: delete character in SET1.  -s: replace sequence of characters in SET1 by one  Examples:  tr ‘a‘ 'A' # Translate lower a with A  tr ‘[A-Z]’ ‘[a-z]’ # Translate uppercase to lowercase  tr -d ‘ ‘ # Delete all spaces from file GNU textutils voorbeelden Character conversion

 paste [options] [files...  Options:  -d #: delimiter: Use # for the delimiter.  -s: serial: paste one file at a time.  Examples:  paste f1 f2 # Display line of f1 followed by f2.  paste -d: file1 file2 # Use ':' for the delimiter. GNU textutils voorbeelden Regel manipulatie - paste

 join [options] [files]  Options:  -1 FIELD: Join on FIELD in file 1  -2 FIELD: Join on FIELD in file 2  -j FIELD : equivalent to `-1 FIELD -2 FIELD'  Examples:  join file1 file2 GNU textutils voorbeelden Regel manipulatie - join

 Voor paste/join zie ook: 

 uniq [options] [files...]  Options:  -d: only print duplicated lines.  -u: only print unique lines.  Examples:  uniq -cd file # Display the number of duplicated # line. GNU textutils voorbeelden Dedupliceren

 split [options] file  Options:  -l #: split every # lines.  -b #: split file in bytes or b for 512 bytes, k for kilobytes, m for megabytes.  Examples:  split -l 25 file # Split file into 25-line files.  split -b 512 file # Split file into 512-byte files.  split -b 2b file # Split file into 2*512-byte files. GNU textutils voorbeelden Files splitsen

 fmt [options] [files...]  Options:  -w #: maximum line width.  Examples:  fmt -w 35 file # Display lines with a maximum width # of 35 characters. GNU textutils voorbeelden Formatteren om te printen - fmt

 pr [options] [files...]  Options:  -d: double space.  Examples:  pr -d file # Format file with double-spacing. GNU textutils voorbeelden Formatteren om te printen - pr

 sort [options] [files]  Options:  -r : Reverse  -f : Ignore case  -n: Numeric  -o file: Redirect output to file  -u: No duplicate records  -t; : Use ';' as delimiter, rather than tab or space.  Examples:  sort file -ro result GNU textutils voorbeelden Sorteren van regels

 od [options] file  Options:  -c: each byte as a character  -x: 2-byte in hex  -d: 2-byte in decimal  -X: 4-byte in hex  -D: 4-byte in decimal  Examples:  od -cx /bin/ls GNU textutils voorbeelden Binary filedump

Oefenen

 Candidates should be able to manipulate files and text data using regular expressions. This objective includes creating simple regular expressions containing several notational elements. It also includes using regular expression tools to perform searches through a filesystem or file content.  Key Knowledge Areas  Create simple regular expressions containing several notational elements.  Use regular expression tools to perform searches through a filesystem or file content.  Boek: 4.5 LPI Search text files using regular expressions

 Twee soorten  Wildcards (file name generation)  *  ?  [ - ]  ~  quotes  Regexp (Regular expression)  Wildcards in regexp generen geen bestandsnamen  Regexp tools  grep/egrep, vi, sed Pattern matching

 * ? [] ~  Quotes:  “ ” double quotes (suppress expansion)  ls “c*”  ` ` back quotes (command substitution)  echo "The contents of this directory are " `ls - l` > dir.txt  ‘’ single quotes (no change)  echo '$HOME'  Zie ook:  Wildcards

Regular expressions Het vinden van tekenreeksen

Regular expressions Hoe vaak?

 grep [options] [string] [files]  Options:  -i: Ignore case  -E: Extended, use regular expressions  -l: List filename only if at least one matches  -c: Display only count of matched lines  -n: Also display line number  -v: Must not match grep

 Examples:  grep host /etc/*.conf  grep -l '\<mai' /usr/include/*.h  grep -n toto /etc/group  grep -vc root /etc/passwd  grep '^user' /etc/passwd  grep '[rR].*' /etc/passwd  grep '\<[rR].*' /etc/passwd

 sed [address1][,address2][!]command[options] [files...]  Options:  Too many sed

 Examples:  sed –n /or/p users  sed –n /^or/p users  sed –n /./p users  sed –n /\./p users  sed –n ‘/\./’p users  sed s/home/users/g users

 Zie ook:  Oefenen

 Candidates should be able to edit text files using vi. This objective includes vi navigation, basic vi modes, inserting, editing, deleting, copying and finding text.  Key Knowledge Areas  Navigate a document using vi.  Use basic vi modes.  Insert, edit, delete, copy and find text.  Boek: 4.1 LPI Perform basic file editing operations using vi

 Universal text editor  Twee modes:  Command mode  Input mode  Cheat sheet:  vi

Vi Opslaan en afsluiten

Vi Knippen, kopiëren en plakken

Vi Manouvreren door tekstbestand

 :s/oud/nieuw/g  Vervang alle keren oud met nieuw op huidige regel  :%s/oud/nieuw/g  Vervang alle keren oud met nieuw op alle regels Vi Zoeken en vervangen

Oefenen

 “Hardware en het opzetten van Filesystemen”  Lees in boek:  13.1: De functie van de kernel (p )  13.2: Beheer van kernelmodules (p )  13.3: Aanpassen van kernel-parameters (p )  5: Beheer van opslag ( )  Herhaal de opdrachten van bijeenkomst 4 Huiswerk: