The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Substr throws an ERROR. Any alternatives? naseert Shell Programming and Scripting 3 05-08-2008 12:34 PM
double dashes systemsb UNIX for Dummies Questions & Answers 2 05-18-2006 10:41 AM
help removing dashes from social security number Marcia P UNIX for Dummies Questions & Answers 2 02-28-2006 09:10 PM
fwrite throws segmentation fault fermisoft High Level Programming 6 09-13-2005 01:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-25-2007
kingdbag kingdbag is offline
Registered User
  
 

Join Date: Jun 2006
Location: Las Vegas, NV
Posts: 104
grep throws in dashes?

Hey guys,

I'm trying to grep for two things out of a file and I got that working but why is it randomly throwing "--" in the output? Is there a simple way to get rid of them? It only seems to do it when the line above what im looking for has numbers in it.

Code:
$ egrep -i -B 1 'port-name|description' in.txt
127.0.0.1
description
--
127.0.0.2
description
--
127.0.0.3
description
helpme
port-name
yay
port-name
  #2 (permalink)  
Old 04-27-2007
srinivasan_85 srinivasan_85 is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 28
See if this helps??

Hi,
I've seen something similar to this while using "gnu grep". If you simply grep for something, only those lines containing the search-pattern will be displayed. But if u issue "gnu grep -1 'search-pattern' file", you will get the lines immediately before and after the line containing the search-pattern.

In your case, it gives the line just before the line containing search-pattern, i guess.

There is a chance that your "egrep" may be aliased to "gnu egrep", or at least you are using the version of egrep inside the gnu folder.

It would be kind of you, if you would explain the functionality of "-B" option. I wasnt able to ascertain..

Thanks,
Srini

Last edited by srinivasan_85; 04-27-2007 at 07:54 AM.. Reason: Typographical mistakes
  #3 (permalink)  
Old 04-27-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,318
It's not randomly, it's by design, from "man grep"
Quote:
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing -- between contiguous
groups of matches.
, so it's being used kinda as separator.
  #4 (permalink)  
Old 04-27-2007
kingdbag kingdbag is offline
Registered User
  
 

Join Date: Jun 2006
Location: Las Vegas, NV
Posts: 104
Yea i'm using a GNU grep for this... "A" fetches lines below what you are looking for and "B" grabs lines above. I just created a perl script to strip them out before it writes to a new file. I'm terrible with using sed, awk, nawk etc.... so that was quickest fix for me.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0