Presentation is loading. Please wait.

Presentation is loading. Please wait.

基于UNIX操作系统的 编程技术 电子科技大学计算机学院 刘玓 联系方式:

Similar presentations


Presentation on theme: "基于UNIX操作系统的 编程技术 电子科技大学计算机学院 刘玓 联系方式:"— Presentation transcript:

1 基于UNIX操作系统的 编程技术 电子科技大学计算机学院 刘玓 联系方式:www.uestc.edu.cn教师社区或
2019年4月27日

2 引 言 课程内容和特点简介 主要教学难点 学习方法建议 教学要求和安排 教材及参考书 《UNIX Shell 实例精解》(第二版)
中国电力出版社,2002年9月出版 Ellie Quigley 著 张茹 译

3 本课程内容 第一章 正则表达式 第二章 流编辑器 sed 第三章 编程工具 awk 第四章 shell交互功能和shell变量
第一章 正则表达式 第二章 流编辑器 sed 第三章 编程工具 awk 第四章 shell交互功能和shell变量 第五章 shell程序设计 第六章 shell程序调试

4 第一章 正则表达式 一. 定义 什么是正则表达式? 正则表达式(Regular Expression, RE)
第一章 正则表达式 一. 定义 什么是正则表达式? 正则表达式(Regular Expression, RE) 是一种字符模式,用来在一次搜索中匹 配具有相同形式的字符或字符串。

5 二. 正则表达式的形式 封装在一对正斜线中的单词(word) 例如: /file/ /student/ /123abc/ /[Uu]estc/ /*computer$/

6 说明: 1. “单词(word)”的定义 两个单词间隔符之间的字符串 单词间隔符包括: ① 空白符 空格、回车、换行、制表、文件结束 ② 普通标点符号

7 2. 单词的长度: 1~n个字符 . 1个字符 字符串的特殊形式 . n > 80 (屏幕的自然行长) 自动卷行, 无回车换行符

8 3. 正则表达式在输入数据中以行为单 位查找匹配的字符串 . why ? 行间隔符(回车换行)同时也是字符 串间隔符 . 一行中可能的多次匹配 存在多次匹配时的分别处理

9 4. 正则表达式中的单词中常常使用特 殊元字符来表示某种要查找的范围 或类型 例如: * 匹配任意多个前导字符 匹配单个任意字符 [] 匹配括号中枚举的任何一个字符 \ 给一个元字符转义 (参见 p27 表2.1 前半部分 )

10 5. 正则表达式的主要使用范围 . 屏幕编辑程序 vi、edit等 . 应用编程工具 grep、sed、awk 等 . 命令行编辑 可方便重复前面发过的某条命令 . Shell程序设计 变量名、文件名的表示

11 三. 正则表达式的应用实例 $vi picnic
I had a lovely time on our little picnic. Lovers were all around us. It is springtime. Oh love, how much I adore you. Do you know the extent of my love? Oh, by the way, I think I lost my gloves somewhere out in that field of clover. Did you see them? I can only hope love is forever. I live for you. It’s hard to get back in the groove. ~

12 I had a lovely time on our little picnic.
Lovers were all around us. It is springtime. Oh love, how much I adore you. Do you know the extent of my love? Oh, by the way, I think I lost my gloves somewhere out in that field of clover. Did you see them? I can only hope love is forever. I live for you. It’s hard to get back in the groove. ~ /love/ (查找所有包含love的字符串)

13 I had a lovely time on our little picnic.
Lovers were all around us. It is springtime. Oh love, how much I adore you. Do you know the extent of my love? Oh, by the way, I think I lost my gloves somewhere out in that field of clover. Did you see them? I can only hope love is forever. I live for you. It’s hard to get back in the groove. ~ /[Ll]ove/ (查找所有包含love和Love的字符串)

14 I had a lovely time on our little picnic.
Lovers were all around us. It is springtime. Oh love, how much I adore you. Do you know the extent of my love? Oh, by the way, I think I lost my gloves somewhere out in that field of clover. Did you see them? I can only hope love is forever. I live for you. It’s hard to get back in the groove. ~ /o*ve/ (查找以零到多个o开始后跟ve的字符串)


Download ppt "基于UNIX操作系统的 编程技术 电子科技大学计算机学院 刘玓 联系方式:"

Similar presentations


Ads by Google