Review of grep

Table 4.3. Review of grep

Command

What It Does

grep '\<Tom\>' file

Prints lines containing the word Tom.

grep 'Tom Savage' file

Prints lines containing Tom Savage.

grep '^Tommy' file

Prints lines if Tommy is at the beginning of the line.

grep '\.bak$' file

Prints lines ending in .bak. Single quotes protect the dollar sign ($) from interpretation.

grep '[Pp]yramid' *

Prints lines from all files containing pyramid or Pyramid in the current working directory.

grep '[A–Z]' file

Prints lines containing at least one capital letter.

grep '[0–9]' file

Prints lines containing at least one number.

grep '[A–Z]...[0–9]' file

Prints lines containing five-character patterns starting with a capital letter and ending with a number.

grep –w '[tT]est' files

Prints lines with the word Test and/or test.

grep –s 'Mark Todd' file

Finds lines containing Mark Todd, but does not print the lines. Can be used when checking grep's exit status.

grep –v 'Mary' file

Prints all lines not containing Mary.

grep –i 'sam' file

Prints all lines containing sam, regardless of case (e.g., SAM, sam, SaM, sAm).

grep –l 'Dear Boss' *

Lists all filenames containing Dear Boss.

grep –n 'Tom' file

Precedes matching lines with line numbers.

grep "$name" file

Expands the value of variable name and prints lines containing that value. Must use double quotes.

grep '$5' file

Prints lines containing literal $5. Must use single quotes.

ps –ef| grep '^ *user1'

Pipes output of ps –ef to grep, searching for user1 at the beginning of a line, even if it is preceded by zero or more spaces.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值