Uso del comando GREP
domenica 31 gennaio 2010

Option



Definition



-i



Searches for both uppercase ande lowercase characters



-l



lists the names of files with marching lines



-n



Precedes each line with the relative line number in the file



-v



Inverts the search to display lines that do not match th
pattern



-c



Counts the lines that contain the pattern



-w



Searches for tehe expression as a complete word,ignoring
those matches that are substrings of larger




Esempi:

1) cerca la stringa root nel file /etc/group e mi restituisce il numero della linea

$ grep -n root /etc/group

1:root::0:

2:other::1:root

3:bin::2:root,daemon

4:sys::3:root,bin,adm

5:adm::4:root,daemon

6:uucp::5:root

7:mail::6:root

8:tty::7:root,adm

9:lp::8:root,adm

10:nuucp::9:root

12:daemon::12:root

$cd /etc

$ grep -l root group passwd hosts

group

passwd

$ grep -c root group

11

Examples of using regular expression metacharacters


$ grep '^no' /etc/passwd
nobody:x:60001:60001:NFS Anonymous Access User:/:
noaccess:x:60002:60002:No Access User:/:
nobody4:x:65534:65534:SunOS 4.x NFS Anonymous Access User:/:


$ grep 'A...n' /etc/passwd
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico
listen:x:37:4:Network Admin:/usr/net/nls:


$ grep 'adm$' /etc/group
sys::3:root,bin,adm
tty::7:root,adm
lp::8:root,adm




postato da Eduardo Kislanski @ 09:17  

0 Commenti:

Posta un commento

<< Home page

MARVEL and SPIDER-MAN: TM & © 2007 Marvel Characters, Inc. Motion Picture © 2007 Columbia Pictures Industries, Inc. All Rights Reserved. © 2007 Sony Pictures Digital Inc. All rights reserved.