CS313 Fall 2004
LAB 3

FIRST VI DAY

This is an easy test to see if you can handle vi.

Don't forget:   gets you out of insert mode.  If you are
ever confused, hit  then u (to undo your last bad commands).

To refresh your memory, you want to move around a file using
/, to find a string, fx, to find the x in the line, w to move
around a word, - to move up, and  to move down.

You can do things like cw to change a word, or i to insert, or a
to append.  o to open a new line.  cfn to change until you find an n.

Y to yank a line, p to paste.  P to paste ahead of the cursor.
3Y to yank three lines.  yfn to yank from here to the first n.

j goes down in the same column.  . repeats the last destructive command.

:wq or :q! to write, or to quit without saving changes.

1.  I want you to go to this URL:

	http://stlouis.cardinals.mlb.com/NASApp/mlb/stl/stats/stl_sortable_player_stats.jsp?baseballScope=sln&subScope=pos&teamPosCode=all&statType=Overview&timeSubFrame=22&sitSplit=&venueID=&Submit=Submit&timeFrame=1

and I want you to grab the hitting stats for each of the cardinals players.
If you don't like the cardinals, feel free to use the boston red sox players
instead.

If that URL is too long, try 

	http://stlouis.cardinals.mlb.com/NASApp/mlb/stl/stats/stl_sortable_player_stats.jsp

and I don't care if you use the season stats or the postseason or whatever.

I want you to use your mouse to copy the data and the names and paste
it into your vi editor window.  You will have to have a terminal window
or ssh window open and have said % vi myname to the shell to be in
the editor.  Don't forget to be in INSERT MODE when you do the paste!
Otherwise it'll interpret all the characters as commands, and that will
be very bad!

2.  Now I want you to look at this format for the batters files for
our baseball simulator:

Womack	l	ab=53	b1=9	b2=1	b3=1	b4=0	bb=2	sf=0	sb=1	k=7	stb=3	cs=0
Womack	r	ab=53	b1=9	b2=1	b3=1	b4=0	bb=2	sf=0	sb=1	k=7	stb=3	cs=0
Walker	l	ab=56	b1=6	b2=4	b3=1	b4=6	bb=6	sf=0	sb=0	k=15	stb=1	cs=0
Walker	r	ab=56	b1=6	b2=4	b3=1	b4=6	bb=6	sf=0	sb=0	k=15	stb=1	cs=0
Molina	l	ab=5	b1=1	b2=0	b3=0	b4=0	bb=0	sf=0	sb=0	k=0	stb=0	cs=0
Molina	r	ab=5	b1=1	b2=0	b3=0	b4=0	bb=0	sf=0	sb=0	k=0	stb=0	cs=0

etc.

Do you see how there is a discrepancy?

3.  Now I want you to change the data you just grabbed so that it conforms to
the file format we need.  You don't have access to sf and sb data on the
first page, so don't worry about that.

First, don't worry about the l and r lines being different.  Just get the
ab= and b1= stuff to be right.  Actually, you have hits instead of b1,
so you can say h= instead of b1=.

What I recommend doing is going into the first line, say Womack, and
using w to move over until you have the number for ab's.  Then say
iab=.  This will put the ab= where you want it.  Then go to the
next line with  and use 3w or 5w or however many words you
need to move over, then say . to repeat the last command.  This will
really impress upon you the need to think about your commands before
you do them so that you do them in a way that is easy to repeat.

4.  Now insert the "l" on each line so that each batter's stats are
against left-handed pitching.  Now replicate each line by saying Y then P
to yank and put.  Then change every other line's "l" to an "r".  This will
give righty and lefty stats to each batter.

5.  Delete from each line any data that are not associated with a prefix
such as ab=.  You'll want to delete the batting and slugging averages, for
example.  You'll also want to delete the STL and the player positions.

6.  Change all the spaces into tabs.  First, try to do this yourself.
Then ask the TA for a good way to do this using 

	:s/ /	/g

or even 

	:g/./ s/ /	/g 

which are wonderful ways to change things.

7.  That's it!