|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hi all
I have an file: 980<tab>980 981 981 982 982 983 983 984 984 985 985 986 986 987 987 988 988 989 989 990 990 991 991 992 992 993 993 994 994 I hope I can using "^99\d" to list 99x or using "^992\t" to list "992" but that don't work , why? I have tried using [\d]... , no use. thank you very much key9 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2006-12-02, key9 wrote:
> hi all > > I have an file: > 980<tab>980 > 981 981 > 982 982 > 983 983 > 984 984 > 985 985 > 986 986 > 987 987 > 988 988 > 989 989 > 990 990 > 991 991 > 992 992 > 993 993 > 994 994 > > > > I hope I can using "^99\d" to list 99x > or using "^992\t" to list "992" > > but that don't work , why? > > I have tried using [\d]... , no use. grep '^99[0-9]' grep '^992' -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> grep '^992' this will also list 9920 take a look at this format is int<tab>string 70 xxx 74 xxx 75 xxx 750 anc 7500 bcd I want show 7x line whe I using '^7[0-9]' it will also list 750 7500 but \t will not work : '^7[0-9]\t' |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Hello,
> > grep '^992' > > > this will also list 9920 > > > take a look at this > format is > > int<tab>string > > 70 xxx > 74 xxx > 75 xxx > 750 anc > 7500 bcd > > > I want show 7x line > > whe I using '^7[0-9]' > > it will also list 750 7500 > but \t will not work : '^7[0-9]\t' Use "\s" to specify that there is a "space character" after your 7x pattern: grep '^7[0-9]\s' HTH, Loic. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
"key9" <iamkey9@126.com> writes:
> take a look at this > format is > > int<tab>string > > 70 xxx > 74 xxx > 75 xxx > 750 anc > 7500 bcd > > I want show 7x line grep '^7[0-9][[:space:]]' -- Best regards, _ _ .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo-- |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
> grep '^7[0-9]\s' ok it works but I wanna know why '^7[0-9]\t' not work? Actually I generated this file using c++ std::cout << int << "\t" << string_ << std::endl; and I using some hex editor exam the file , the "blank" is <tab> :-) Dose \s means "human readable blank?" |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Hold on
it'still not work: cat file > grep '^12\s' using this code to generate file,we named the bin gener #include <iostream> #include <string> using namespace c++ int main() { int la = 0; int ua = 2000; for(int i = la; i != ua; ++i){ cout << i << "\t" << i << endl; } } gener > file cat file > grep '^12\s' I suppose it will display 12 12 but it display nothing |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
> using namespace c++ sorry using namespace std; |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
2006-12-2, 19:18(+08), key9:
> Hold on > > it'still not work: > cat file > grep '^12\s' [...] That command will concatenate the content of the "file" and "^12\s" files and store that in a file called "grep" in the current directory. grep '^12[[:blank:]]' < file TAB=`printf '\t'` grep "^12$TAB" standard greps don't necessarily recognise any of those \s, \t, \d... awk recognises \t: awk '/^12\t/' -- Stéphane |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
key9 wrote:
>>grep '^992' > > this will also list 9920 > > take a look at this > format is > > int<tab>string > > 70 xxx > 74 xxx > 75 xxx > 750 anc > 7500 bcd > > I want show 7x line > > whe I using '^7[0-9]' > > it will also list 750 7500 > but \t will not work : '^7[0-9]\t' Try any of... grep '^7[0-9]\>' grep -w '^7[0-9]' grep '^7[0-9][ ]' # there's a space and a tab inside the [] Janis |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
Hi,
> Hold on > > it'still not work: > cat file > grep '^12\s' Of course, it doesn't work! Your last command should read: $ cat file | grep '^12\s' or even better: $ grep '^12\s' file the \s means "white space" which expands to something like: [ \f\n\r\t\v] Cheers, Loic. |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
2006-12-2, 14:44(-08), loic-dev@gmx.net:
> Hi, > >> Hold on >> >> it'still not work: >> cat file > grep '^12\s' > > Of course, it doesn't work! Your last command should read: > $ cat file | grep '^12\s' > > or even better: > $ grep '^12\s' file > > the \s means "white space" which expands to something like: > [ \f\n\r\t\v] [...] In which version of grep is \s such a thing? Even GNU grep doesn't seem to recognise \s. \s is a blank (that is [ \t]) in perl (and perl compatible regular expressions) and vim, that I know of. GNU grep can be compile with PCRE support in which case you can do: grep -P '^12\s' (still for [ \t]). You could do: perl -lne 'print if /^12\s/' standard greps have [[:blank:]] for blank ([ \t]) and [[:space:]] for space ([ \f\n\r\t\v]). -- Stéphane |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
2006-12-3, 00:28(+00), Stephane CHAZELAS:
> 2006-12-2, 14:44(-08), loic-dev@gmx.net: >> Hi, >> >>> Hold on >>> >>> it'still not work: >>> cat file > grep '^12\s' >> >> Of course, it doesn't work! Your last command should read: >> $ cat file | grep '^12\s' >> >> or even better: >> $ grep '^12\s' file >> >> the \s means "white space" which expands to something like: >> [ \f\n\r\t\v] > [...] > > In which version of grep is \s such a thing? Even GNU grep > doesn't seem to recognise \s. > > \s is a blank (that is [ \t]) in perl (and perl compatible > regular expressions) and vim, that I know of. [...] My bad, \s is space ([ \f\n\r\t\v]) in perl/pcre and tcl (in newer versions, inspired from perl), and blank ([ \t]) in vim. > > GNU grep can be compile with PCRE support in which case you can > do: grep -P '^12\s' (still for [ \t]). Would be [ \f\n\r\t\v] then. -- Stéphane |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
Stephane CHAZELAS wrote:
> 2006-12-3, 00:28(+00), Stephane CHAZELAS: >>2006-12-2, 14:44(-08), loic-dev@gmx.net: >> >>In which version of grep is \s such a thing? Even GNU grep >>doesn't seem to recognise \s. >> >>\s is a blank (that is [ \t]) in perl (and perl compatible >>regular expressions) and vim, that I know of. > [...] > > My bad, \s is space ([ \f\n\r\t\v]) in perl/pcre and tcl (in > newer versions, inspired from perl), and blank ([ \t]) in vim. Perl doesn't have a "\v" character so \s is [ \f\n\r\t]. If you want the vertical tab included then use [[:space:]]. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall |
|
![]() |
| Outils de la discussion | |
|
|