LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2010, 01:57 PM   #1
ohijames
LQ Newbie
 
Registered: Jun 2010
Posts: 17

Rep: Reputation: 0
Grep ignoring spaces or tabs


I writing a script to go through multiple reports. I want to grep daemon.debug @10.10.10.10 on all reports to make sure it is pointing to the right IP address. the problems is the space between debug and @10 are different on all the reports, some have one space some have two and some have tabs how do I ignore the tabs or spaces and grep daemon.debug @10.10.10.10

daemon.debug /var/log/ftp rotate size 20m files 4 compress
daemon.debug @10.10.10.10
authpriv.* /var/log/secure rotate size 20m files 4 compress
authpriv.* @10.10.10.10
 
Old 06-29-2010, 02:04 PM   #2
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Use \s for matching any whitespace character (like space or tab).

e.g. grep -E "daemon\.debug\s+@10\.10\.10\.10"

Last edited by zirias; 06-29-2010 at 02:07 PM. Reason: regex syntax
 
Old 06-29-2010, 02:05 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
egrep 'daemon.debug[[:blank:]]*@10\.10\.10\.10' filename
 
Old 06-29-2010, 02:07 PM   #4
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 97
or just
Code:
grep "daemon.debug @10.10.10.1"
or
Code:
grep daemon.debug\ @10.10.10.1
 
Old 06-29-2010, 02:08 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by zirias View Post
Use \s for matching any whitespace character (like space or tab).

e.g. grep -E "daemon.debug\s+@10\.10\.10\.10"
Matches one or more "whitespace characters", whereas mine matches zero or more.

<<you fixed 2nd comment while I was typing>>

Last edited by pixellany; 06-29-2010 at 02:09 PM.
 
Old 06-29-2010, 02:49 PM   #6
ohijames
LQ Newbie
 
Registered: Jun 2010
Posts: 17

Original Poster
Rep: Reputation: 0
@ Pixellany

that worked but do you know why the command below doesn't work the same
grep "daemon.debug[[:blank:]]/var/log/ftp" newfile.txt
 
Old 06-29-2010, 02:52 PM   #7
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
that matches EXACTLY one whitespace character (btw, \s is just shorthand for [[:blank:]]). If you want to match one or more, append a + (and a * for zero or more)

btw, you are using grep. for regular expression matching, you must use "grep -E" (or egrep, which is shorthand for grep -E)

Last edited by zirias; 06-29-2010 at 02:54 PM. Reason: Ha, overlooked something
 
  


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
Spaces vs. Tabs, and a specific question about space indenting. golmschenk Programming 24 02-28-2010 08:10 AM
Geany - How do you convert tabs to spaces? golmschenk Linux - Software 6 02-27-2010 04:06 PM
Replacing Tabs (^T) with spaces.... visitnag Linux - Newbie 3 05-04-2008 03:30 AM
tabs to spaces in emacs, not working in tcl mode ratm1286 Linux - Software 3 05-08-2005 05:15 PM
emacs - convert auto indent tabs to spaces? BrianK Linux - General 1 04-15-2004 10:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:37 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