Tuesday, November 6, 2007

OPS435W9

We are going to be covering stuff that is more difficult that what we have done so far,
regular expression, awk, sed language.

Looking at Assignment #2:

A program what makes exchange rate do, take any currency of any country and your program will exchange it to anyother country
from the exchange rate.


Done in 2 stages,

Stage 1, evalaluation varification of input, Nov 16
Stage 2, 2 weeks later

Being Partnersz we are going to use the RCS system

Between the two partners who accounts to use

In that persons home directory ~/asgm2/***/exchange.bash & RCS

710/ 710 / 770/ 770 / 770 /



#GroupMember:
#GroupMember:

The rates are freezed as of today and put on a table on the site

convert.table will reflect the data in that file

cad
CAD
Cad



2arg cad us


Oc can do anything mathimatics


sed -nl | file

We are going to use regular expressions, subject of our lecture today

What are they used for?
To match patterns in data


You can use similar special chars to search for patters in data, called regular expression.


grep 'patt' f1

FNE * - zero or more
RE * - Zero or more of the previous char

FNE . - is dot
RE . - any single char

FNE ? -any single char
RXE ? - is a ? extended regular expression -egrep -awk - zero or one of the previous char


FNE - [!dfds]
RE - [^Fdsa]

RE - ^a[^fds]d - specifies the begining of the line because the other one does any pattern within the line
$ - its the end of the line, this belongs at the end of ^^ that line

.* - zero or more any character, combine those two<---

RE - a\{3\}b - a repeater refereing to the previous char which is a, how many a's their are, 3 a's followed by a b = aaab.
,5 - min 3 max 5, longest pattern first then the shortest

RXE - a+b - extended regular expression - one or more of the previous char. shortest patt ab.

RE - a+b|c?d - the pipe is a or

grep - can use RE - single pattern
egrep - can use RXE - multiple pattern by using the or which is the |


grep 'a+b|c?d' f1 - none are special chars to grep
egrep 'a+b|c?d' f1 - 1 or more a's followed by a b OR zero or 1 c's followed by a d


echo $1|grep '^[0-9]\{8\}$'

(( *sum *= *$?AA *+ *$?BB *))

sed

:S,$ s/exchange/convert/g - in vi

g = globably
no g only first match each line

sed - stream line editor, tell sed what to make to data

sed -op 'address sub-comm/searchpattern/replacepatt/tag' data

some options:

-n
-f
-e

address :

2,10 - only lines through 2 to 10 do the stuff
can also use RE
2,/dog.s/ - start at line 2 next line must have dogs or dogs
/dog.s/,15
1,$ - line 1 to the end of the file
subcommands cover:
s - search
i
a
c

Search pattern:
-RE - here

replacement pattern:
does not use RE

tags:
g - global
d - delete
p


How sed actually really works

has a pattern space buffer,
opens the file takes line number 1 first thing it does check the line number, automatically line 1 goes to STNOUT
Next line comes in #2, address match yes then continue with the rest, if we say s subtitute search for a pattern it will
replace it with that pattern.

sed '/^$/d' f1 - delete blank lines

No comments: