linux三剑客grep,sed,awk

grep

官方帮助文档

Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c

Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression (ERE)
  -F, --fixed-strings       PATTERN is a set of newline-separated fixed strings
  -G, --basic-regexp        PATTERN is a basic regular expression (BRE)
  -P, --perl-regexp         PATTERN is a Perl regular expression
  -e, --regexp=PATTERN      use PATTERN for matching
  -f, --file=FILE           obtain PATTERN from FILE
  -i, --ignore-case         ignore case distinctions
  -w, --word-regexp         force PATTERN to match only whole words
  -x, --line-regexp         force PATTERN to match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline

Miscellaneous:
  -s, --no-messages         suppress error messages
  -v, --invert-match        select non-matching lines
  -V, --version             print version information and exit
      --help                display this help and exit
      --mmap                use memory-mapped input if possible

Output control:
  -m, --max-count=NUM       stop after NUM matches
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines
      --line-buffered       flush output on every line
  -H, --with-filename       print the filename for each match
  -h, --no-filename         suppress the prefixing filename on output
      --label=LABEL         print LABEL as filename for standard input
  -o, --only-matching       show only the part of a line matching PATTERN
  -q, --quiet, --silent     suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE;
                            TYPE is `binary', `text', or `without-match'
  -a, --text                equivalent to --binary-files=text
  -I                        equivalent to --binary-files=without-match
  -d, --directories=ACTION  how to handle directories;
                            ACTION is `read', `recurse', or `skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets;
                            ACTION is `read' or `skip'
  -R, -r, --recursive       equivalent to --directories=recurse
      --include=FILE_PATTERN  search only files that match FILE_PATTERN
      --exclude=FILE_PATTERN  skip files and directories matching FILE_PATTERN
      --exclude-from=FILE   skip files matching any file pattern from FILE
      --exclude-dir=PATTERN directories that match PATTERN will be skipped.
  -L, --files-without-match print only names of FILEs containing no match
  -l, --files-with-matches  print only names of FILEs containing matches
  -c, --count               print only a count of matching lines per FILE
  -T, --initial-tab         make tabs line up (if needed)
  -Z, --null                print 0 byte after FILE name

Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM
      --color[=WHEN],
      --colour[=WHEN]       use markers to highlight the matching strings;
                            WHEN is `always', `never', or `auto'
  -U, --binary              do not strip CR characters at EOL (MSDOS)
  -u, --unix-byte-offsets   report offsets as if CRs were not there (MSDOS)

`egrep' means `grep -E'.  `fgrep' means `grep -F'.
Direct invocation as either `egrep' or `fgrep' is deprecated.
With no FILE, or when FILE is -, read standard input.  If less than two FILEs
are given, assume -h.  Exit status is 0 if any line was selected, 1 otherwise;
if any error occurs and -q was not given, the exit status is 2.

Report bugs to <[email protected]>.

sed

官方帮助文档

Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

  -n, --quiet, --silent
                 suppress automatic printing of pattern space
  -e script, --expression=script
                 add the script to the commands to be executed
  -f script-file, --file=script-file
                 add the contents of script-file to the commands to be executed
  --follow-symlinks
                 follow symlinks when processing in place
  -i[SUFFIX], --in-place[=SUFFIX]
                 edit files in place (makes backup if extension supplied)
  -l N, --line-length=N
                 specify the desired line-wrap length for the `l' command
  --posix
                 disable all GNU extensions.
  -r, --regexp-extended
                 use extended regular expressions in the script.
  -s, --separate
                 consider files as separate rather than as a single continuous
                 long stream.
  -u, --unbuffered
                 load minimal amounts of data from the input files and flush
                 the output buffers more often
      --help     display this help and exit
      --version  output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret.  All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

awk

官方帮助文档

Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:          GNU long options: (standard)
        -f progfile             --file=progfile
        -F fs                   --field-separator=fs
        -v var=val              --assign=var=val
Short options:          GNU long options: (extensions)
        -b                      --characters-as-bytes
        -c                      --traditional
        -C                      --copyright
        -d[file]                --dump-variables[=file]
        -D[file]                --debug[=file]
        -e 'program-text'       --source='program-text'
        -E file                 --exec=file
        -g                      --gen-pot
        -h                      --help
        -i includefile          --include=includefile
        -l library              --load=library
        -L[fatal|invalid]       --lint[=fatal|invalid]
        -M                      --bignum
        -N                      --use-lc-numeric
        -n                      --non-decimal-data
        -o[file]                --pretty-print[=file]
        -O                      --optimize
        -p[file]                --profile[=file]
        -P                      --posix
        -r                      --re-interval
        -S                      --sandbox
        -t                      --lint-old
        -V                      --version

To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
        gawk '{ sum += $1 }; END { print sum }' file
        gawk -F: '{ print $1 }' /etc/passwd

原文地址:https://www.cnblogs.com/fiany/p/11526329.html

时间: 2024-11-09 14:43:12

linux三剑客grep,sed,awk的相关文章

Linux三剑客grep/sed/awk

grep/sed/awk被称为linux的“三剑客” grep更适合单纯的查找或匹配文本: sed更适合编辑匹配到的文本: awk更适合格式化文本,对文本进行较复杂各式处理: Grep --color=auto 或者 --color:表示对匹配到的文本着色显示 -i:在搜索的时候忽略大小写 -n:显示结果所在行号 -c:统计匹配到的行数,注意,是匹配到的总行数,不是匹配到的次数 -o:只显示符合条件的字符串,但是不整行显示,每个符合条件的字符串单独显示一行 -v:输出不带关键字的行(反向查询,反

linux三剑客---grep,sed,awk与正则表达式

grep命令: grep全称:Global Regular Expression Print,即全面搜索正则表达式并把行打印出来,通过参数-E可以使用egrep的功能 grep与egrep的区别:在于grep只支持基础正则表达式,而egrep可以支持扩展的正则表达式 常用用法: [[email protected] ~]# grep [-acinv] [--color=auto] '搜寻字符串' filename 选项与参数: -a :将 binary 文件以 text 文件的方式搜寻数据 -c

六、三剑客grep/sed/awk

6.1.正则表达式  正则表达式: 是一类字符所书写出的模式(pattern):元字符:不表示字符本身的意义,用于额外功能性的描述.  1) 基本正则表达式: BRE元字符: .: 匹配任意单个字符 [char]: 匹配指定范围内的任意单个字符 [^char]:匹配指定范围外的任意单个字符 字符集合: [:digit:], [:lower:], [:upper:], [:punct:], [:space:], [:alpha:], [:alnum:] 匹配次数( 贪婪模式) : *: 匹配其前面

Linux命令-grep,sed,awk

grep (global search regular expression[RE] and print out the line) 正则表达式全局搜索并将行打印出来 在文件中查找包含字符串"text"的行 grep text local_file grep "text" local_file #另一种方式 grep "text" local_file1 local_file2 ... #查找多个文件 在文件中查找不包含字符串"text

Linux三剑客 grep、awk、seed

简介 grep:适合单纯的查找或匹配文本 sed:适合编辑文本 awk:适合格式化文本,对文本进行复杂的格式化处理 1.grep grep -help [options] -c:只输出匹配行的计数 -i:不区分大小写 -h:查询多文件是不显示文件名 -l:查询多文件时只输出包含匹配字符的文件名 -m:显示匹配行及行号 -s:不显示不存在或无匹配文本的错误信息 -v:显示不包含匹配文本的所有行 -color=auto:可以将找到的关键词部分加上颜色的显示 [pattern]正则参数含义 \:忽略正

深入浅出linux三剑客之sed必杀技一例

转 http://oldboy.blog.51cto.com/2561410/949365 缘起:上完培训课后,同学们对sed加正则处理问题的热情高涨,氛围相当好,但是,有个别同学还是有些晕乎,因此,撰写此文.此例如果搞熟练了,sed和正则的大部分常用技术你掌握起来就简单了. 如果还有不会的,老男孩就拿出最后的讲解必杀技(先保密,嘿!),同学们想不会那是不可能的,除非你们自己主动放弃,哈哈.来,开整~! 老男孩linux培训第三节课程课前第考试一题,问题如下 1.如何取得/etiantian文件

LINUX 下 find grep sed awk 的常见基本用法特点

LINUX 下 find grep sed awk 的常见基本用法特点 只为让自己具有更高的水准,这就开始了长达6个月的小白进阶路! 这几天学习linux基础命令有点犯蒙,尤其是对文件查找这块.所有我想把一些我觉得常用的实用的参数项总结下来,大神勿喷哈... 不到之处请大家指教,小女子在此谢过了. 一.find:命令用于查找文件系统中指定的文件,其命令格式为: 1.find pathname -options [ -print  -exec  -ok ... ] (1)find 命令的参数: p

不看绝对后悔的Linux三剑客之sed实战精讲

二.Linux三剑客之sed命令精讲 1,前言 我们都知道,在Linux中一切皆文件,比如配置文件,日志文件,启动文件等等.如果我们相对这些文件进行一些编辑查询等操作时,我们可能会想到一些vi,vim,cat,more等命令.但是这些命令效率不高,这就好比一块空地准备搭建房子,请了10个师傅拿着铁锹挖地基,花了一个月的时间才挖完,而另外一块空地则请了个挖土机,三下五除二就搞定了,这就是效率.而在linux中的"挖土机"有三种型号:顶配awk,中配sed,标配grep.使用这些工具,我们

grep,sed,awk与简单正则表达式应用

grep,sed,awk与简单正则表达式应用 这里使用的测试文件是linux /etc/passwd文件,最好是复制一份进行练习,方式对文件内容造成损坏.感觉还是要多练习才能很好的使用,习题这里就不贴了,网上一找一大把. grep:   -o 用作计算出现多少次字段  -c 打印符合要求的行数  -n 在输出符合要求的行的同时也打印行号  -v 打印不符合要求的行  -A 后跟一个数字 ps -A2表示打印符合要求的行及下面两行  -B 后跟一个数字 ps -B2表示打印符合要求的行及上面两行 

linux三剑客之sed史上最实用教程!

2016老男孩教育的官方博客干货不断,敬请关注! linux三剑客之sed史上最实用教程!猛戳下面地址即可观看! http://blog.oldboyedu.com/commands-sed/