lecture8

lecture8 - Sed Awk Lecture 8: Using RegExps with Sed and...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Sed Awk Lecture 8: Using RegExps with Sed and Awk CS2042 - UNIX Tools October 17, 2008 Lecture 8: Sed and Awk
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sed Awk The Translate Command Intro to Stream Editing Some Practical Examples Lecture Outline 1 Sed The Translate Command Intro to Stream Editing Some Practical Examples 2 Awk What is Awk? Awk Variables Lecture 8: Sed and Awk
Background image of page 2
Sed Awk The Translate Command Intro to Stream Editing Some Practical Examples When to Script What if we wanted to. .. Change a Notepad-style text file to Unix-style? Strip directory prefixes from a path? Print certain columns from a text file? Remove all the comment lines from some code? How much time/effort/code would it take to do this stuff in C/C++/Java? Stuff like this is the reason scripting was created - you can get each task done in a line or two. Lecture 8: Sed and Awk
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sed Awk The Translate Command Intro to Stream Editing Some Practical Examples Search and Replace with TR The Translate Command tr [options] < set1 > [set2] Translate or delete characters Sets are strings of characters Only works on STDIN/STDOUT - use redirection to translate files! By default, searches for strings matching set1 and replaces them with set2 tr -c < set1 > [set2] will complement set1 before replacing it with set2 tr -d < set1 > deletes the characters in set1 without translating anything. Lecture 8: Sed and Awk
Background image of page 4
Sed Awk The Translate Command Intro to Stream Editing Some Practical Examples TR Examples Example: Try echo * - it prints everything in the directory, separated by spaces. Let’s separate them by newlines instead: echo * | tr ’ ’ ’/n’ - replaces all spaces with newlines Example: Let’s print a file in all uppercase: tr ’a-z’ ’A-Z’ < test.txt - prints the contents of text.txt in all caps Lecture 8: Sed and Awk
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sed Awk The Translate Command Intro to Stream Editing Some Practical Examples Redirection Revisited Bash processes I/O redirection from left to right, allowing us to do fun things like this:
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/23/2009 for the course CS 2042 taught by Professor Mccourt during the Fall '08 term at Cornell.

Page1 / 21

lecture8 - Sed Awk Lecture 8: Using RegExps with Sed and...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online