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. Visual Assist X 10.8.2052的Crack破解补丁. 2014.11.05 (General release.)

    VA小组立即更新频率似有些放缓几乎,版本号都是2个月才更新一次,而这次的更新幅度也还是比較大的,新增了6个特性,而且修正和20余处大大小小的问题,而且也是正式发行版,推荐更新. 对于破解补丁还是老规矩 ...

  2. hdu5171(矩阵快速幂)

    传送门:GTY's birthday gift 题意:GTY的朋友ZZF的生日要来了,GTY问他的基友送什么礼物比较好,他的一个基友说送一个可重集吧!于是GTY找到了一个可重集S,GTY能使用神犇魔法 ...

  3. mongodb在PHP下的应用学习笔记

    1.连接 mongodb默认端口是:27017,因此我们连接mongodb:$mongodb = new Mongo('localhost') 或者指定IP与端口 $mongodb = new Mon ...

  4. 番外:android模拟器连不上网

    1.删除你PC端得备用DNS,只留一个即可.确保能够上网. 注意:这个虽然不是必须的,出错点也不一定在他,但是我建议这样做,因为我们不确定到底模拟器和我们的PC是否使用的是一个DNS,不是的话,就会造 ...

  5. Perl中检测标准输入使用的字符集

    #Perl中检测标准输入使用的字符集 sub locale_encode{ my $lang = $ENV{'LANG'}; my $dot_pos = rindex($lang, '.'); my ...

  6. 每日算法之三十八:Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  7. HDU 4940(杭电更多的学校#7 1006) Destroy Transportation system(到处乱混)

    职务地址:pid=4940">HDU 4940 当时这个题一看就看出来了是网络流的最小割.然后就一直在想建图. .然后突然发现,应该要让T集合的数目最少,不然仅仅要有两个,那这两个的每 ...

  8. 在Xshell中上传下载文件到本地(linux中从多次ssh登录的dbserver里面的文件夹)

    在Xshell中上传下载文件到本地(linux中从多次ssh登录的dbserver里面的文件夹) 1 列出所有需要copy的sh文件 -bash-4.1$ ll /mysqllog/osw/*.sh ...

  9. SCSI miniport 驾驶一个简单的框架

    前段时间,只需用一台新电脑,由于资金有限没有匹配了心仪已久的SSD.我没感觉到飞翔的感觉,总不甘心,仔细想想.我死了相当大的存储,我们可以假设部分内存作为硬盘驱动器把它弄出来.不会比固态硬盘的速度快, ...

  10. c#和UDP SOCKET广播

    server:  Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,ProtocolType.Udp); // ...