week 10 - mar 21, 20051 “searching and replacing” in vi week 10 agenda
Post on 27-Dec-2015
216 Views
Preview:
TRANSCRIPT
Week 10 - Mar 21, 2005 2
Letter of Employment
Dear INT120 student,
Congratulations!
Based on the excellent reference provided by your highly-respected INT120 professor...
General Motors is pleased to offer you the position of IS&S intern at a starting salary of $50,000 (USD)
Week 10 - Mar 21, 2005 3
Letter of Employment
Your benefits include:6 weeks paid holidays your choice of company car
Your probationary period lasts 3 months....during that time you must complete all work on timewith “zero defects”.
Good luck! Michael Grimaldi, President GM Canada
Week 10 - Mar 21, 2005 4
Your first AssignmentGeneral Motors has just purchased these 4 companies:
Hummer AMC Saab Vauxhall
Week 10 - Mar 21, 2005 5
Update all the GM files immediately so that all the old company names are replaced with General Motors.
Note: This has to be done quickly so that there will be no “Insider Trading” scandals
Your first Assignment
Week 10 - Mar 21, 2005 6
So...
$1,000 bonus
..if you complete thisin the next 5 minutes!
Your first Assignment
Week 10 - Mar 21, 2005 7
Tip - for Big $’s
In the workplace much of your time will be spent editing existing files
These files might be text files, scripts, or web pages
Week 10 - Mar 21, 2005 8
You do this with the vi editor
Your vi editing skills are needed to:
1. pass INT120
2. pass OPS235, OPS330, OPS440,and INT440
3. keep your job in a UNIX environment
Week 10 - Mar 21, 2005 9
Searching & Substituting in vi
The substitute command
:[address]s/search-string/replacement-string[/option]
Do not panic!
We’ll learn it 1 step at a time!
Week 10 - Mar 21, 2005 10
Searching & Substituting in vi
The substitute command
: [address]s/search-string/replacement-string[/option]
starts with a colon all vi commands that begin with a colon are executed at the
status line (ex mode or last line mode)
Week 10 - Mar 21, 2005 11
Searching & Substituting in viThe substitute command
:[address]s/search-string/replacement-string [/option]
can be nothing - will search only current line single line number - will search that line only line number,line number - search those two line
and all lines in between
Week 10 - Mar 21, 2005 12
Searching & Substituting in viThe substitute command
:[address]s/search-string/replacement-string [/option]
period - current line $ - last line in the work buffer % - entire work buffer
Week 10 - Mar 21, 2005 13
Searching & Substituting in vi
The substitute command:[address]Address Part of Work Buffer
searched 27 line 27
3,10 lines 3 through 10 inclusive
1,$ entire work buffer
Week 10 - Mar 21, 2005 14
Searching & Substituting in vi
The substitute command
:[address]s/search-string/replacement-string [/option]
the S after the address is the substitute command the / forward slash is the delimiter indicating the beginning
of the search-string
Week 10 - Mar 21, 2005 15
Searching & Substituting in vi
The substitute command
:[address]s/search-string/replacement-string
[/option]
The search-string is the regular expression you are looking for - the “pattern” you want to match.....
Week 10 - Mar 21, 2005 16
Searching & Substituting in vi
The substitute command
:[address]s/search-string/replacement-string [/option]
The replacement-string is the string that you want to use to replace the pattern you matched.
Week 10 - Mar 21, 2005 17
Searching & Substituting in vi
The substitute command:[address]s/search-string/replacement-string
[/option]with no option vi will only replace the first occurrence on a line if a search-string match is found.
/g option substitutes all occurrences (globally)
Week 10 - Mar 21, 2005 24
Your Turn!
Follow the directions on your handout to edit the “General Motors” pricelist
The first group to complete this task with “zero defects” gets a BONUS!
Week 10 - Mar 21, 2005 25
Your Second Assignment
Some of our web pages aren’t loading properly.
Spot the mistakes in the code and get promoted to Chief Web Site Administrator....
top related