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. android画笔错位问题的解决

    下面的画画板的代码: public class MainActivity extends Activity { private ImageView iv; private Bitmap baseBit ...

  2. poj 1991 Turning in Homework dp

    这个可以证明必须从两边的任务开始交起,因为中间交的任务可以后面经过的时候再交,所以就变成了一个n*n的dp. #include <iostream> #include <cstdio ...

  3. 7.MongoDB java CRUD

    注意:要增加mongodb对应的jar包 package cn.toto.mongodb; import java.net.UnknownHostException; import org.bson. ...

  4. python socket编程实现的简单tcp迭代server

    与c/c++ socket编程对照见http://blog.csdn.net/aspnet_lyc/article/details/38946915 server: import socket POR ...

  5. JavaScript模板引擎

    JavaScript模板引擎实例应用   在之前的一篇名为<移动端基于HTML模板和JSON数据的JavaScript交互>的文章中,我向大家说明了为什么要使用JavaScript模板以及 ...

  6. OPEN-E安装中注意的问题

    安装OPEN-E的时候,OPEN-E需要单独安装到存储硬盘外的硬盘上,否则是没有办法使用安装了OPEN-E的硬盘上的空间的. OPEN-E免费许可证的容量问题 安装OPEN-E后申请的试用key只能试 ...

  7. android2.2应用开发之IccCard(sim卡或USIM卡)

    tyle="margin:20px 0px 0px; font-size:14px; line-height:26px; font-family:Arial; color:rgb(51,51 ...

  8. 学习 easyui 之二:jQuery 的 ready 函数和 easyloader 的加载回调函数

    Ready 事件不一定 ready 使用 easyloader 的时候,必须要注意到脚本的加载时机问题,easyloader 会异步加载模块,所以,你使用的模块不一定已经加载了.比如下面的代码. &l ...

  9. Eclipse关闭检查

    有没有发现每次操作Eclipse过后,都会有build Workspace的操作一直在后台执行,JS校验一直validate,非常卡非常受不了有木有? 有木有?以下是我个人成功的步骤,曾经试过非常多次 ...

  10. 【PhotoShop】采用PS让美丽的咖啡泡沫

    稀土一杯咖啡,如何你不能击败张(常苦黑咖啡饮料实在受不了! ) 得到例如以下图 看着还不错,但是总感觉空空荡荡的,所以就拿来PS练手了.终于效果图例如以下: 以下讲下制作过程: 首先是给照片加下咖啡泡 ...