Lab 8 Introduction to String Processing

Sequence 1: Exercises in string processing

1. Other than the man page, how could you get a summary of options for the aspell command,
displayed one page at a time?
aspell --help | less

2. How many files are in the directory /usr/bin?
ls /usr/bin | wc -l

3. List the misspelled words in the /usr/share/doc/HTML/index.html file.
aspell list < /usr/share/doc/HTML/index.html

4. How many times does each misspelled word appear?
aspell list < /usr/share/doc/HTML/index.html | sort | uniq -c

5. Display the /etc/passwd line for any account that starts with the letter g
grep '^g' /etc/passwd
cat /etc/passwd | grep '^g'

6. Display the number of lines in /etc/passwd
wc -l /etc/passwd
cat /etc/passwd | wc -l

7. Display a list of usernames (and no other data) from /etc/passwd
cut -d: -f1 /etc/passwd

8. Display the /etc/passwd line for any account that is using the bash shell
grep 'bash$' /etc/passwd

9. Display the /etc/passwd line for any account that is not using the bash shell
grep -v 'bash$' /etc/passwd

10. Display a list of files in /etc/ that contain the word root. Display only the filenames and
do not print errors
grep -l root /etc/* 2> /dev/null

11. Display the shell being used by root, as stored in /etc/passwd.
grep '^root:' /etc/passwd | cut -d: -f7

Sequence 2: diff and patch

1. [student@stationX ~]$ cp /etc/issue ~/issue

2. vi ~/issue
Welcome to \n (\l)!
Red Hat Enterprise Linux Server release 5
Kernel \r on an \m

3. [student@stationX ~]$ diff /etc/issue ~/issue

4. [student@stationX ~]$ diff -u /etc/issue ~/issue > /tmp/issue.patch

5. [student@stationX ~]$ cat /tmp/issue.patch
+ represents a line that should be added
- represents a line that should be removed

6. [root@stationX ~]# patch -b /etc/issue /tmp/issue.patch

7. [student@stationX ~]$ diff -u /etc/issue ~/issue

8. [root@stationX ~]# restorecon /etc/issue
restore file(s) default SELinux security contexts.

9. [root@stationX ~]# patch -R /etc/issue /tmp/issue.patch
[root@stationX ~]# cp /etc.issue.org /etc/issue

Sequence 3: Stream editing with regular expressions

vi cats
cat
catalog
concatenate
polecat
Cat

1. sed 's/cat/dog/' cats
dog
dogalog
condogenate
poledog
Cat

2. sed 's/^[Cc]at/dog/' cats
dog
dogalog
concatenate
polecat
dog

3. sed 's/^cat$/dog/i' cats
dog
catalog
concatenate
polecat
dog

[student@stationX ~]$ sed '10,35s/cat/dog/' pets
[student@stationX ~]$ sed '/digby/,/duncan/s/cat/dog/' pets
[student@stationX ~]$ sed -e 's/cat/dog/g' -e 's/cow/goat/g' pets

vi myedits
s/cat/dog/g
s/cow/goat/g

[student@stationX ~]$ sed -f myedits pets

RH033读书笔记(7)-Lab 8 Introduction to String Processing的更多相关文章

  1. RH033读书笔记(15)-Lab 16 The Linux Filesystem

    Lab 16 The Linux Filesystem Goal: Develop a better understanding of Linux filesystem essentials incl ...

  2. RH033读书笔记(2)-Lab 3 Getting Help with Commands

    Lab 3 Getting Help with Commands Sequence 1: Using the Help Tools 1. man -f keyword whatis keyword l ...

  3. RH033读书笔记(5)-Lab 6 Exploring the Bash Shell

    Lab 6 Exploring the Bash Shell Sequence 1: Directory and file organization 1. Log in as user student ...

  4. RH033读书笔记(4)-Lab 5 File Permissions

    Lab 5 File Permissions Sequence 1: Determining File Permissions 1. What is the symbolic representati ...

  5. RH033读书笔记(3)-Lab 4 Browsing the Filesystem

    Lab 4 Browsing the Filesystem Sequence 1: Directory and File Organization 1. Log in as user student ...

  6. RH033读书笔记(6)-Lab 7 Standard I/O and Pipes

    Lab 7 Standard I/O and Pipes 1. [student@stationX ~]$ cat /proc/cpuinfo /proc/meminfo 2. [student@st ...

  7. RH033读书笔记(8)-Lab 9 Using vim

    Lab 9 Using vim Sequence 1: Navigating with vim 1. Log in as user student 2. [student@stationX ~]$ c ...

  8. RH033读书笔记(10)-Lab 11 Process Control

    Lab 11 Process Control Sequence 1: Job Control 1. [student@stationX ~]$ su - 2. Begin some jobs in t ...

  9. RH033读书笔记(9)-Lab 10 Understanding the Configuration Tools

    Lab 10 Understanding the Configuration Tools Sequence 1: Configuring the Network with system-config- ...

随机推荐

  1. linux find命令强大之处

    find命令 find pathname -options [-print -exec -ok ...]   -print: find命令将匹配的文件输出到标准输出.   -exec: find命令对 ...

  2. hdu2444(判二分图+最大匹配)

    传送门:The Accomodation of Students 题意:有n个学生,m对相互认识的,问能否分成两队,使得每对中没有相互认识的,如果可以求最大匹配,否则输出No. 分析:判断二分图用染色 ...

  3. rm -vf `ls |egrep -v "info_20130826-180233.31764|QueryParser.INFO"`

    > rm -vf `ls |egrep -v "info_20130826-180233.31764|QueryParser.INFO"`

  4. hdu2870(dp求最大子矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2870 分析:分别转换成'a','b','c'三种来求,其实就跟hdu1505一样了... #inclu ...

  5. Java 兑换ObjectC代码

    现在非常多app发展,server我们使用Java发展,实时数据交换,与Android非常easy实现.是否xml依然是json,它可以很容易地转换成一个对象.这可以是硬IOS该程序猿.它们应根据数据 ...

  6. linux下golang

    linux下golang的配置 linux下golang的配置 之前开发golang一直在windows下,今天在linux下试了一下 ,遇到一些梗,比如go 找不到 sync包.花了一小时全部解决, ...

  7. shiro权限架作战

    shiro框架作为一种特权的开源框架,通过身份验证和授权从具体的业务逻辑分离极大地提高了我们的发展速度,它的易用性使得它越来越受到人们的青睐.上一页ACL架相比,shiro能更easy的实现权限控制, ...

  8. 2012 PHP热门资料64个+经典源码50个——下载目录 :

    完整附件0豆下载:http://down.51cto.com/data/419216 附件部分预览: PHP精彩应用实例程序源码集锦 http://down.51cto.com/zt/39 无师自通: ...

  9. 日版 Galaxy Note sc05d 涮机

    问题描写叙述:手机已坏.进不了系统 以下提供线涮刷机教程: 1.首先拔掉你的sd卡和sim卡.双清你的手机.可能有些版本号的机油没有双清模式,那就进到设置里边恢复出厂设置,然后关掉你的手机再开机.等到 ...

  10. Oracle连接池

    原由:许多用户可能在查询相同的数据库以获取相同的数据.在这些情况下,可以通过使应用程序共享到数据源的连接来提高应用程序的性能.否则,让每个用户打开和关闭单独的连接的开销会对应用程序性能产生不利影响.这 ...