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. [Cocos2d-x]布局与定位

    游戏中,精灵的位置由Position与AnchorPoint同时决定. Scene 锚点 (0,0) 不启用锚点 CCNode锚点 (0,0) 不启用锚点  CCLayer锚点 (0,0) 不启用锚点 ...

  2. Graphical Shell with WebShell - WebOS Internals

    Graphical Shell with WebShell - WebOS Internals Graphical Shell with WebShell From WebOS Internals J ...

  3. git配置流程

    写的比较简略,主要是记录一下,以后配置别的机器的时候看一下,仅供参考. 1 安装 命令依赖包 sudo apt-get install git-core git-gui git-doc 2 设置SSH ...

  4. poj3311(状压dp)

    题目连接:http://poj.org/problem?id=3311 题意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. 分析:跑一遍Floyd ...

  5. hdu1330(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1330 分析:经典问题,n 块相同的木板重叠,最多能够伸出桌面多远 对于n张卡片的最佳摆法,我们只需要在 ...

  6. SE 2014年4月22日(二)

    如图配置: 网络中存在三个公有AS 其中AS200使用了 BGP联盟技术(如图配置) 在AS 100 中R1上起源了四条BGP路由,(1)要求全网BGP设备均能够正常学习 (2)要求:(使用BGP团体 ...

  7. MVAPI第一个版本架构图

    MVAPI采用矢量与栅格结合的方式进行移动地图的显示. 进过几个月,目前终于可以完成基本的地图显示及操作功能.还有待实现的是各种性能及效果优化.3D地物等. 发一个1.0的架构图留存一下.(虽然目前还 ...

  8. NYOJ 104 最大子矩阵(二维DP)

    最大和 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描写叙述 给定一个由整数组成二维矩阵(r*c),如今须要找出它的一个子矩阵,使得这个子矩阵内的全部元素之和最大,并把这个 ...

  9. Leetcode 细节实现 Set Matrix Zeroes

    Set Matrix Zeroes Total Accepted: 18139 Total Submissions: 58671My Submissions Given a m x n matrix, ...

  10. Oracle 数据迁移(从Oracle11G迁移到更高的版本号Oracle10G低版本号)

    1.数据库状况    生产环境是11G,linux系统,測试环境是10G,windows系统,须要从生产环境导出一个用户下全部的数据,导入測试环境中. 由于数据量比較小,准备採用EXP和IMP工具来做 ...