To: All Employees
From: Human Resources
In order to better serve the needs of our mass market customers, ABC Publishing is integrating the groups selling to this channel for ABC General Reference and ABC Computer Publishing. This change will allow us to better coordinate our selling and marketing efforts, as well as simplify ABC's relationships with these customers in the areas of customer service, co-op management, and credit and collection. Two national account managers, Ricky Ponting and Greeme Smith, have joined the sales team as a result of these changes.
To achieve this goal, we have also organized the new mass sales group into three distinct teams reporting to our current sales directors, Stephen Fleming and Boris Baker. I have outlined below the national account managers and their respective accounts in each of the teams. We have also hired two new national account managers and a new sales administrator to complete our account coverage. They include:
Sachin Tendulkar, who joins us from XYZ Consumer Electronics as a national account manager covering traditional mass merchants.
Brian Lara, who comes to us via PQR Company and will be responsible for managing our West Coast territory.
Shane Warne, who will become an account administrator for our warehouse clubs business and joins us from DEF division.
Effectively, we have seven new faces on board:
1. RICKY PONTING
2. GREEME SMITH
3. STEPHEN FLEMING
4. BORIS BAKER
5. SACHIN TENDULKAR
6. BRIAN LARA
7. SHANE WARNE
Please join me in welcoming each of our new team members.
举一个简单的例子来说,要查找包含 “welcoming” 单词的行,最好的方法是使用下面的命令行:
# grep welcoming memo
Please join me in welcoming each of our new team members.
|
如果您想查找单词 “market”,结果会有很大的不同,如下所示:
# grep market memo
In order to better serve the needs of our mass
market customers, ABC Publishing is
integrating the groups selling to this channel
for ABC General Reference and ABC Computer
Publishing. This change will allow us to
better coordinate our selling and marketing
efforts, as well as simplify ABC's
relationships with these customers in the
areas of customer service, co-op management,
and credit and collection. Two national
account managers, Ricky Ponting and Greeme
Smith, have joined the sales team as a result
of these changes.
|
注意我们找到了两个匹配项:我们希望找的 “market” 和 “marketing”。如果在这个文件中还存在 “marketable” 或 “marketed” 之类的单词,那么上面的命令也会显示包含这些单词的行的内容。
在 grep 中可以使用通配符和元字符,我强烈建议将它们放到引号中,这样 shell 就不会将它们解释成命令了。
要查找所有包含数字的行,请使用下面的命令:
# grep "[0-9]" memo
1. RICKY PONTING
2. GREEME SMITH
3. STEPHEN FLEMING
4. BORIS BAKER
5. SACHIN TENDULKAR
6. BRIAN LARA
7. SHANE WARNE
|
要查找所有包含 “the” 的行,请使用下面的命令:
# grep the memo
In order to better serve the needs of our mass
market customers, ABC Publishing is
integrating the groups selling to this channel
for ABC General Reference and ABC Computer
Publishing. This change will allow us to
better coordinate our selling and marketing
efforts, as well as simplify ABC's
relationships with these customers in the
areas of customer service, co-op management,
and credit and collection. Two national
account managers, Ricky Ponting and Greeme
Smith, have joined the sales team as a result
of these changes.
To achieve this goal, we have also organized
the new mass sales group into three distinct
teams reporting to our current sales
directors, Stephen Flemming and Boris Baker. I
have outlined below the national account
managers and their respective accounts in each
of the teams. We have also hired two new
national account managers and a new sales
administrator to complete our account
coverage. They include:
|
正如您可能已经注意到的一样,输出结果中包含了单词 “these”,还有单词 “the” 的一些精确匹配。
grep 工具,与很多其他 UNIX/Linux 工具一样,都是大小写敏感的,这意味着查找 “The” 和 “the” 会产生完全不同的结果。
# grep The memo
To achieve this goal, we have also organized
the new mass sales group into three distinct
teams reporting to our current sales
directors, Stephen Flemming and Boris Baker. I
have outlined below the national account
managers and their respective accounts in each
of the teams. We have also hired two new
national account managers and a new sales
administrator to complete our account
coverage. They include:
|
如果您想查找一个特定的单词或短语,但却不太关心它们的大小写,那可以使用两种方法。第一种方法是使用方括号同时查找 “The” 和 “the”,如下所示:
# grep "[T, t]he" memo
In order to better serve the needs of our mass
market customers, ABC Publishing is
integrating the groups selling to this channel
for ABC General Reference and ABC Computer
Publishing. This change will allow us to
better coordinate our selling and marketing
efforts, as well as simplify ABC's
relationships with these customers in the
areas of customer service, co-op management,
and credit and collection. Two national
account managers, Ricky Ponting and Greeme
Smith, have joined the sales team as a result
of these changes.
To achieve this goal, we have also organized
the new mass sales group into three distinct
teams reporting to our current sales
directors, Stephen Flemming and Boris Baker. I
have outlined below the national account
managers and their respective accounts in each
of the teams. We have also hired two new
national account managers and a new sales
administrator to complete our account
coverage. They include:
|
第二种方法是使用 -i
选项,这告诉 grep 忽略大小写的敏感性。
# grep -i the memo
In order to better serve the needs of our mass
market customers, ABC Publishing is
integrating the groups selling to this channel
for ABC General Reference and ABC Computer
Publishing. This change will allow us to
better coordinate our selling and marketing
efforts, as well as simplify ABC's
relationships with these customers in the
areas of customer service, co-op management,
and credit and collection. Two national
account managers, Ricky Ponting and Greeme
Smith, have joined the sales team as a result
of these changes.
To achieve this goal, we have also organized
the new mass sales group into three distinct
teams reporting to our current sales
directors, Stephen Flemming and Boris Baker. I
have outlined below the national account
managers and their respective accounts in each
of the teams. We have also hired two new
national account managers and a new sales
administrator to complete our account
coverage. They include:
|
除了 -i
选项之外,还有另外几个命令行选项可以用来改变 grep 的输出结果。最常见的选项如下所示:
-c
—— 屏蔽正常输出;相反,打印每个输入文件的匹配行数。
-l
—— 屏蔽正常输出;相反,打印包含正常输出内容的每个输入文件的名字。
-n
—— 在每行输出前面加上该行在输入文件中的行号作为前缀。
-v
—— 将匹配意义进行逆反 —— 即选择那些不 匹配搜索条件的行。
fgrep
会对文件搜索某个字符串,并打印包含这个字符串的所有行的内容。与 grep 不同的是,fgrep 搜索的是一个字符串,而不是可以匹配某个表达式的一种模式。fgrep 可以看作是 grep 在以下方面进行了增强:
- 一次可以搜索多个对象。
- fgrep 工具通常速度都比 grep 更快。
- 我们不能使用 fgrep 来搜索使用模式的正则表达式。
假设我们希望从前面的 memo 文件中提取全部由大写字母组成的名字。为了查找 “STEPHEN” 和 “BRIAN”,我们需要执行两个单独的 grep 命令,如下所示:
# grep STEPHEN memo
3. STEPHEN FLEMING
# grep BRIAN memo
6. BRIAN LARA
|
使用 fgrep,只需要一个命令就可以实现相同的任务:
# fgrep "STEPHEN
> BRIAN" memo
3. STEPHEN FLEMING
6. BRIAN LARA
|