LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-19-2010, 03:57 PM   #1
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
grep related question...


What does this actually do or how does it search:

Code:
arg=testserver

grep -lsi "^[^ ]*: .*$arg" /tmp/list
 
Old 11-19-2010, 04:06 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
It searches /tmp/list.

grep options, from man grep:
Quote:
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output
would normally have been printed. The scanning will stop on the first match. (-l
is specified by POSIX.)

-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input files. (-i is specified
by POSIX.)

-s, --no-messages
Suppress error messages about nonexistent or unreadable files. Portability note:
unlike GNU grep, 7th Edition Unix grep did not conform to POSIX, because it lacked
-q and its -s option behaved like GNU grep’s -q option. USG-style grep also lacked
-q but its -s option behaved like GNU grep. Portable shell scripts should avoid
both -q and -s and should redirect standard and error output to /dev/null instead.
(-s is specified by POSIX.)
Now the regular expression:
Code:
^[^ ]*: .*$arg
- Beginning of line (^)
- Anything but a space ([^ ]) zero or more times (*)
- A colon
- A space
- Any character, zero or more times (.*)
- $arg, in this case, "testserver"

So it searches /tmp/list for lines that start with some non-space characters followed by a colon, then a space then anything until the word "testserver". If there's a match it will print "/tmp/list".

A good regex resource: http://www.regular-expressions.info

Last edited by AlucardZero; 11-19-2010 at 04:07 PM.
 
Old 11-19-2010, 05:52 PM   #3
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Original Poster
Rep: Reputation: 73
Thanks very much!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep question tekmann33 Linux - Newbie 1 08-11-2008 11:22 AM
maybe a grep question: me210 Linux - Software 3 01-19-2007 12:13 PM
Grep related: checking for This AND That topcat Programming 3 04-01-2005 03:41 AM
c related question. blackzone Programming 1 07-24-2004 08:55 AM
grep and framebuffer errors... related? kodiakmook Linux - Software 2 01-29-2002 07:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration