Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "LPI 2010 NLLGG Trainer: Jeroen van Pelt Bijeenkomst 4:Werken met tekstbestanden 27.3.2010."— Presentation transcript:

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

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

3  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: 4.2-4.3-4.4-4.5 LPI 103.2 Process text streams using filters

4  http://gnu.typhon.net/software/textutils/textutils.html http://gnu.typhon.net/software/textutils/textutils.html  Tools om tekstbestanden en streams te filteren GNU textutils-1

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

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

7  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

8  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

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

10  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

11  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.

12  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

13  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.

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

15  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.

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

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

18  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

19  Voor paste/join zie ook:  http://bit.ly/bGBnkI http://bit.ly/bGBnkI

20  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

21  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

22  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

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

24  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

25  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

26 Oefenen

27  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 103.7 Search text files using regular expressions

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

29  * ? [] ~  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:  http://bit.ly/9KnDvW http://bit.ly/9KnDvW Wildcards

30 Regular expressions Het vinden van tekenreeksen

31 Regular expressions Hoe vaak?

32  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

33  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

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

35  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

36  Zie ook:  http://bit.ly/4sp7De http://bit.ly/4sp7De Oefenen

37  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 103.8 Perform basic file editing operations using vi

38  Universal text editor  Twee modes:  Command mode  Input mode  Cheat sheet:  http://bit.ly/98xm1D vi

39 Vi Opslaan en afsluiten

40 Vi Knippen, kopiëren en plakken

41 Vi Manouvreren door tekstbestand

42  :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

43 Oefenen

44  “Hardware en het opzetten van Filesystemen”  Lees in boek:  13.1: De functie van de kernel (p329-335)  13.2: Beheer van kernelmodules (p336-341)  13.3: Aanpassen van kernel-parameters (p341-345)  5: Beheer van opslag (119-164)  Herhaal de opdrachten van bijeenkomst 4 Huiswerk: 17.4.2010


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

Similar presentations


Ads by Google