Mercurial > hg > toybox
comparison toys/pending/grep.c @ 971:31e91deb0824
grep: add -b flag
author | Strake |
---|---|
date | Sun, 08 Jun 2003 10:15:17 -0500 |
parents | 55794a3d35c5 |
children | e33f0312de6e |
comparison
equal
deleted
inserted
replaced
970:55794a3d35c5 | 971:31e91deb0824 |
---|---|
3 * Copyright 2013 CE Strake <strake888 at gmail.com> | 3 * Copyright 2013 CE Strake <strake888 at gmail.com> |
4 * | 4 * |
5 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ | 5 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ |
6 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html | 6 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html |
7 | 7 |
8 USE_GREP(NEWTOY(grep, "EFHahinosvwclqe*f*m#", TOYFLAG_BIN)) | 8 USE_GREP(NEWTOY(grep, "EFHabhinosvwclqe*f*m#", TOYFLAG_BIN)) |
9 | 9 |
10 config GREP | 10 config GREP |
11 bool "grep" | 11 bool "grep" |
12 default n | 12 default n |
13 help | 13 help |
14 usage: grep [-clq] [-EFHhinosvw] (-e RE | -f REfile | RE) [file...] | 14 usage: grep [-clq] [-EFHbhinosvw] (-e RE | -f REfile | RE) [file...] |
15 | 15 |
16 modes: | 16 modes: |
17 default: print lines from each file what match regular expression RE. | 17 default: print lines from each file what match regular expression RE. |
18 -c: print the number of matching lines in each file. | 18 -c: print the number of matching lines in each file. |
19 -l: print all matching file names. | 19 -l: print all matching file names. |
21 | 21 |
22 flags: | 22 flags: |
23 -E: extended RE syntax | 23 -E: extended RE syntax |
24 -F: fixed RE syntax, i.e. all characters literal | 24 -F: fixed RE syntax, i.e. all characters literal |
25 -H: print file name | 25 -H: print file name |
26 -b: print byte offset of match | |
26 -h: not print file name | 27 -h: not print file name |
27 -i: case insensitive | 28 -i: case insensitive |
28 -n: print line numbers | 29 -n: print line numbers |
29 -o: print only matching part | 30 -o: print only matching part |
30 -s: keep silent on error | 31 -s: keep silent on error |
71 case 'c': | 72 case 'c': |
72 break; | 73 break; |
73 default: | 74 default: |
74 if (!(toys.optflags & FLAG_h)) printf ("%s:", name); | 75 if (!(toys.optflags & FLAG_h)) printf ("%s:", name); |
75 if ( (toys.optflags & FLAG_n)) printf ("%d:", n); | 76 if ( (toys.optflags & FLAG_n)) printf ("%d:", n); |
77 if ( (toys.optflags & FLAG_b)) printf ("%ld:", lseek (0, 0, SEEK_CUR) - strlen (y) + | |
78 (toys.optflags & FLAG_o ? matches[2].rm_so : 0)); | |
76 if (!(toys.optflags & FLAG_o)) fputs (x, stdout); | 79 if (!(toys.optflags & FLAG_o)) fputs (x, stdout); |
77 else { | 80 else { |
78 y += matches[2].rm_so; | 81 y += matches[2].rm_so; |
79 printf ("%.*s\n", matches[2].rm_eo - matches[2].rm_so, y++); | 82 printf ("%.*s\n", matches[2].rm_eo - matches[2].rm_so, y++); |
80 } | 83 } |