Review Please turn in your homework and practicals sed.

Slides:



Advertisements
Similar presentations
CST8177 sed The Stream Editor. The original editor for Unix was called ed, short for editor. By today's standards, ed was very primitive. Soon, sed was.
Advertisements

Regular Expressions A simple and powerful way to match characters Laurent Falquet, EPFL March, 2005 Swiss Institute of Bioinformatics Swiss EMBnet node.
7 Searching and Regular Expressions (Regex) Mauro Jaskelioff.
Linux+ Guide to Linux Certification, Second Edition
AWK: The Duct Tape of Computer Science Research Tim Sherwood UC San Diego.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
Unix Files, IO Plumbing and Filters The file system and pathnames Files with more than one link Shell wildcards Characters special to the shell Pipes and.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
1 Day 16 Sed and Awk. 2 Looking through output We already know what “grep” does. –It looks for something in a file. –Returns any line from the file that.
Advanced File Processing
Using the Unix Shell There is No ‘Undelete’. The Unix Shell “A Unix shell is a command-line interpreter or shell that provides a traditional user interface.
Linux Tools. Tar tar – (Tape Archive). This is a tool for archiving files and directory hierarchies. tar output can be sent to stdout using the – file.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
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.
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.
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.
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.
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.
Quiz 15 minutes Open note, open book, open computer Finding the answer – working to get it – is what helps you learn I don’t care how you find the answer,
Quiz 30 minutes 10 questions No talking, texting, collaboration, etc…
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
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.
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.
Review Please hand in your practicals and homework Regular Expressions with grep.
Introduction to Unix – CS 21
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
LIN Unix Lecture 7 Hana Filip. LIN Text Processing Command Line Utility Programs (cont.) sed LAST WEEK wc sort tr uniq awk TODAY join paste.
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.
Searching and Sorting. Why Use Data Files? There are many cases where the input to the program may come from a data file.Using data files in your programs.
40 Years and Still Rocking the Terminal!
I/O Redirection & Regular Expressions CS 2204 Class meeting 4 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
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.
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
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.
Review Please turn in your homework and practicals Packages, installation, rpm command Apache – Quick and easy way to set up a web server to play around.
CSC 4630 Meeting 17 March 21, Exam/Quiz Schedule Due to ice, travel, research and other commitments that we all have: –Quiz 2, scheduled for Monday.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
UNIX commands Head More (press Q to exit) Cat – Example cat file – Example cat file1 file2 Grep – Grep –v ‘expression’ – Grep –A 1 ‘expression’ – Grep.
-Joseph Beberman *Some slides are inspired by a PowerPoint presentation used by professor Seikyung Jung, which was derived from Charlie Wiseman.
CSC 352– Unix Programming, Fall 2011 November 8, 2011, Week 11, a useful subset of regular expressions, grep and sed, parts of Chapter 11.
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.
Introduction to Textutils sort, uniq, wc, cut, grep, sed, awk ● Steve Walsh ● Linux Users of Victoria ● November, 2007.
PROGRAMMING THE BASH SHELL PART III by İlker Korkmaz and Kaya Oğuz
Regular Expressions Copyright Doug Maxwell (
Lesson 5-Exploring Utilities
CSE 374 Programming Concepts & Tools
CSC 352– Unix Programming, Spring 2016
Advanced File Processing
CST8177 sed The Stream Editor.
Regular Expression - Intro
Linux command line basics III: piping commands for text processing
Unix Scripting Session 4 March 27, 2008.
Grep Allows you to filter text based upon several different regular expression variants Basic Extended Perl.
CS 403: Programming Languages
CSC 352– Unix Programming, Fall 2012
Guide To UNIX Using Linux Third Edition
Unix Talk #2 grep/egrep/fgrep (maybe add more to this one….)
Unix Talk #2 (sed).
LING 408/508: Computational Techniques for Linguists
CSE 303 Concepts and Tools for Software Development
LPI Linux Certification
Presentation transcript:

Review Please turn in your homework and practicals sed

Today Regular Expressions – Again! – Review grep & sed Again! (The Revenge!) awk

The Guy Who Draws XKCD I think I have a Bash problem. What follows is an actual command from my history. cat /usr/share/dict/words | fgrep -v "'" | perl -ne print join("", ".$_."\n";' | tee lookup.txt | perl -pe 's/^([^ ]+).*/\1/g' | awk '{ print length, $0 }' | sort -n | awk '{$1=""; print $0}' | uniq -c | sort -nr | egrep "^[^0-9]+2 " | awk '{ print length, $0 }' | sort -n | awk '{$1=""; print $0}' | perl -pe 's/[ 0-9]//g' | xargs -i grep {} lookup.txt | perl - pe 's/[^ ]+ //g' | tail -n2 It’s just so hard to bite the bullet, admit that the problem has grown in scope, and move it to its own Perl/Python script. (P.S. The Guinness Book is wrong. “Conservationalists” is not a real word.)

Quick Searching The grep utility is used for matching Printing to STDOUT – an ‘eyeball’ test or redirection to another file grep ‘static string’ file >> redirection grep ‘metacharacters’ file And grep starts at the first line, at the beginning of the row, reads across the row, and as soon as it matches its regex, prints Doesn’t modify, only needs to match once

Replacement The sed utility is used for ‘substitutions’ Can either execute once (by default), or across all entries (globally) Can also print sed ‘s/from/to/g’ file sed -n ‘/regex/p’ file

awk is Awkward Final regex utility is awk For use when your data is evenly formatted Teams.txt last two lines – Seattle Mariners – There might be some guys called the Cubs too – No even formatting First few lines – City Teamname – Even formatting

Example - /etc/passwd smithj:x:561:561:Joe Smith:/home/smithj:/bin/bash smith:*:100:100:8A- 74(office):/home/smith:/usr/bin/sh jsmith:x:1001:1000:John Smith:/home/jsmith:/bin/sh Between each entry is a : Username:Password:UID:GID:Name:Homedir:Shell Empty entries are still “bounded” (ie, :: indicates one empty value)

awk Examples awk -F ‘:’ ‘{ print $1 }’ /etc/passwd awk - command -F ‘:’ - -F sets our ‘delimiter’ to the : character ‘{ print $1 }’ - action /etc/passwd - file to use Prints the first column in the /etc/passwd file – Numbering starts at 1; 0 is the whole file – /etc/passwd is ‘delimited’ by : and empty values still have a : around them

Advanced awk I will not quiz you on this The more powerful awk commands are in scripts – #!/bin/bash – awk ‘\ – BEGIN { print “File\tOwner” } \ – { print $0, “\t”, $3} \ – END { print “ – DONE –” } \ – ‘

Case Study I used awk yesterday Something close to awk -F ‘,’ ‘{ print $1\tprint $7}’ example.csv | sort \ | uniq -c | sort -nr Counting audit findings so that we could see where to concentrate

Unfortunately I had to reimage my laptop over the weekend This wiped out our vm on my system I have basic commands, but they’re not guaranteed to work There may be one question on awk on the final

Finally I have yet to see my son play T-ball I will be “sick” a week from today (Wednesday, June 4 th ) so I can see his last game All late/resubmitted work is due June 9 th Final is Monday, June 16 th during normal class time Just under 50 questions, similar to quizzes

Own Study Regex’s Grep, sed and awk