Monday, September 6, 2010

grep

1. ls -la egrep '^[^d]' > allfiles

2. cat a-j_malenames.txt k-z_malenames.txt > a-z_malenames.text

3. wc -w /usr/local/linuxgym-data/gutenberg/0ws0310.txt > count.output

4. cat /usr/local/linuxgym-data/gutenberg/0ws0310.txt wc –m > pipecount

5. ls /usr/local/linuxgym-data/Gutenberg egrep 'rd' > rdfiles.txt


6. Mkdir s2-files
cd /usr/local/linuxgym-data/gutenberg
cp *s2* s2-files

7. Ls -l sort-r awk '{print $8}' > large_to_small

8. pico wcscript.sh
#!/bin/bash
wc -w $1 awk '{print $1}'
chmod u+x wcscript.sh
./wcscript.sh a.txt

9. egrep -w 'Anne' /usr/local/linuxgym-data/gutenberg/12frd10.txt > anne-words.txt

10. egrep -v '' femalenames.txt egrep '^MAT^NAT' femalenames.txt > natmat.txt

grep

编辑本段1. grep简介  egrep和fgrep的命令只跟grep有很小不同。egrep是grep的扩展,支持更多的re元字符, fgrep就是fixed grep或fast grep,它们把所有的字母都看作单词,也就是说,正则表达式中的元字符表示回其自身的字面意义,不再特殊。linux使用GNU版本的grep。它功能更强,可以通过-G、-E、-F命令行选项来使用egrep和fgrep的功能。
  grep的工作方式是这样的,它在一个或多个文件中搜索字符串模板。如果模板包括空格,则必须被引用,模板后的所有字符串被看作文件名。搜索的结果被送到屏幕,不影响原文件内容。
  grep可用于shell脚本,因为grep通过返回一个状态值来说明搜索的状态,如果模板搜索成功,则返回0,如果搜索不成功,则返回1,如果搜索的文件不存在,则返回2。我们利用这些返回值就可进行一些自动化的文本处理工作。
编辑本段2. grep正则表达式元字符集(基本集)  ^
  锚定行的开始 如:'^grep'匹配所有以grep开头的行。
  $
  锚定行的结束 如:'grep$'匹配所有以grep结尾的行。
  .
  匹配一个非换行符的字符 如:'gr.p'匹配gr后接一个任意字符,然后是p。
  *
  匹配零个或多个先前字符 如:'*grep'匹配所有一个或多个空格后紧跟grep的行。 .*一起用代表任意字符。
  []
  匹配一个指定范围内的字符,如'[Gg]rep'匹配Grep和grep。
  [^]
  匹配一个不在指定范围内的字符,如:'[^A-FH-Z]rep'匹配不包含A-F和H-Z的一个字母开头,紧跟rep的行。
  \(..\)
  标记匹配字符,如'\(love\)',love被标记为1。
  \<
  锚定单词的开始,如:'\  \>
  锚定单词的结束,如'grep\>'匹配包含以grep结尾的单词的行。
  x\{m\}
  重复字符x,m次,如:'o\{5\}'匹配包含5个o的行。
  x\{m,\}
  重复字符x,至少m次,如:'o\{5,\}'匹配至少有5个o的行。
  x\{m,n\}
  重复字符x,至少m次,不多于n次,如:'o\{5,10\}'匹配5--10个o的行。
  \w
  匹配文字和数字字符,也就是[A-Za-z0-9],如:'G\w*p'匹配以G后跟零个或多个文字或数字字符,然后是p。
  \W
  \w的反置形式,匹配一个或多个非单词字符,如点号句号等。
  \b
  单词锁定符,如: '\bgrep\b'只匹配grep。
编辑本段3. 用于egrep和 grep -E的元字符扩展集  +
  匹配一个或多个先前的字符。如:'[a-z]+able',匹配一个或多个小写字母后跟able的串,如loveable,enable,disable等。
  ?
  匹配零个或多个先前的字符。如:'gr?p'匹配gr后跟一个或没有字符,然后是p的行。
  abc
  匹配a或b或c。如:grepsed匹配grep或sed
  ()
  分组符号,如:love(ablers)ov+匹配loveable或lovers,匹配一个或多个ov。
  x,x{m,},x{m,n}
  作用同x\{m\},x\{m,\},x\{m,n\}
编辑本段4. POSIX字符类  为了在不同国家的字符编码中保持一至,POSIX(The Portable Operating System Interface)增加了特殊的字符类,如[:alnum:]是A-Za-z0-9的另一个写法。要把它们放到[]号内才能成为正则表达式,如[A- Za-z0-9]或[[:alnum:]]。在linux下的grep除fgrep外,都支持POSIX的字符类。
  [:alnum:]
  文字数字字符
  [:alpha:]
  文字字符
  [:digit:]
  数字字符
  [:graph:]
  非空字符(非空格、控制字符)
  [:lower:]
  小写字符
  [:cntrl:]
  控制字符
  [:print:]
  非空字符(包括空格)
  [:punct:]
  标点符号
  [:space:]
  所有空白字符(新行,空格,制表符)
  [:upper:]
  大写字符
  [:xdigit:]
  十六进制数字(0-9,a-f,A-F)
编辑本段5. Grep命令选项  -?
  同时显示匹配行上下的?行,如:grep -2 pattern filename同时显示匹配行的上下2行。
  -b,--byte-offset
  打印匹配行前面打印该行所在的块号码。
  -c,--count
  只打印匹配的行数,不显示匹配的内容。
  -f File,--file=File
  从文件中提取模板。空文件中包含0个模板,所以什么都不匹配。
  -h,--no-filename
  当搜索多个文件时,不显示匹配文件名前缀。
  -i,--ignore-case
  忽略大小写差别。
  -q,--quiet
  取消显示,只返回退出状态。0则表示找到了匹配的行。
  -l,--files-with-matches
  打印匹配模板的文件清单。
  -L,--files-without-match
  打印不匹配模板的文件清单。
  -n,--line-number
  在匹配的行前面打印行号。
  -s,--silent
  不显示关于不存在或者无法读取文件的错误信息。
  -v,--revert-match
  反检索,只显示不匹配的行。
  -w,--word-regexp
  如果被\<和\>引用,就把表达式做为一个单词搜索。
  -V,--version
  显示软件版本信息。
编辑本段6. 实例  要用好grep这个工具,其实就是要写好正则表达式,所以这里不对grep的所有功能进行实例讲解,只列几个例子,讲解一个正则表达式的写法。
  $ ls -l grep '^a'
  通过管道过滤ls -l输出的内容,只显示以a开头的行。
  $ grep 'test' d*
  显示所有以d开头的文件中包含test的行。
  $ grep 'test' aa bb cc
  显示在aa,bb,cc文件中匹配test的行。
  $ grep '[a-z]\{5\}' aa
  显示所有包含每个字符串至少有5个连续小写字符的字符串的行。
  $ grep 'w\(es\)t.*\1' aa
  如果west被匹配,则es就被存储到内存中,并标记为1,然后搜索任意个字符(.*),这些字符后面紧跟着另外一个es(\1),找到就显示该行。如果用egrep或grep -E,就不用"\"号进行转义,直接写成'w(es)t.*\1'就可以了。

Thursday, May 28, 2009

week 12 Exhibition

This week, I think we did really good job in the exhibition. Everything works as we expected. although there is some bugs in the playing game animation and high demand for fixation of the projects position, i show lecturer,tutors and visitors a perfect job. The most exciting thing is that our project will be exhibited on the open day. lol,lol.....so happy to see the result that we fight for. i will graduate this semester so that i could not attend the open day this August. but i am so appreciate our project receive recognition from lecturer,tutors and visitors.

At the end, i want to say thank you. thanks Stephen, thanks Marie, thanks Dekker. i know only "thank you "is not enough to describe how i appreciate. But really, thank your guys very much~ Without you guys, our project is nothing!!! Thanks for teaching us a lot!!!

week 11 the last vision of physical & sound effect

Physical book:
This week Stephen gave us suggestion that don’t tie all the pages together by burrow the edge of the book. It will be influent a good looking of the book. Even he tries to help us to modify without redo the physical book. After we discussed, redo the book is the best way to show the high quality to the audience. So redo the physic book is our main works in this week.

Animation part:
Last week, all animations finished the final vision. So this week, I start to import the sound effects into our flash animations. Because we didn’t play any musical instrument, I do some research about the copyright free background music. Then, I use the recorder and Cool edit to record and edit the animal voice. I try to make the voice without the surrounding noise.

week10 Book of original vision & final animation adjust

From this week, we are work together with our individual wroks.

This week we finished the first vision of each page of the book. We want to get feedback from lecturers and tutors. So we have not tied together all pages of the book.



































































Animation part:I have finished all the animation last week. But this week I had to adjust all animations in the right size (800pix X 600pix), high solution.

week9 the last two animations

This week, i finished the last two animations. the first page animation was playing with high solution. But the quiz flash, but the coding part has some problem that i need get help from Dekker. I were get used to write coding in AS2.0, and get lost completely in the As 3.0 language this time. But thanks Dekker taught me a lot so that i could understand how is that work in AS3.0. I think i know what i need to learn next. Yes, it is AS3.0. AS3.0 will be needed in my future work. Here also post ink of those two original vision of animations:
First page animation:http://up.qzone.net.cn/flash6/20090612060035_anmation1.swf
Link for quiz:http://up.qzone.net.cn/flash6/20090612050358_quizas3.swf

week 8 opening aniamtion

This week, the opening animation is beginning to shape up. The scene setting and animation took me a lot time to be perfect in visualy sensation.
opening animation:http://up.qzone.net.cn/flash6/20090612055026_ienv3000--CS4.swf