grep throws in dashes?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep throws in dashes?
# 1  
Old 04-25-2007
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  
Old 04-27-2007
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 08:54 AM.. Reason: Typographical mistakes
# 3  
Old 04-27-2007
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  
Old 04-27-2007
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Filling tab space with dots or dashes

Hey Guys & Gals ! My script is creating a numbered list and I would like to have the numers and results spaced apart by a tab. Now to make sure it is clear which number corresonds with which outcome, I would like to have the tab space filled with dashes. Anyone able to tell me if this... (6 Replies)
Discussion started by: TAPE
6 Replies

2. UNIX for Dummies Questions & Answers

Grepping using -w and dashes (-)

I have a script to sort a list of arbitrary hosts and determine if they are supported by grepping them into a master supported list. I cut all the suffixes of the hosts in the arbitrary list, leaving the "short" hostname if you will, then grep -w them into the master list. For example: ... (1 Reply)
Discussion started by: MaindotC
1 Replies

3. UNIX for Dummies Questions & Answers

scp throws error

My script is like STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 100); printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm') touch $STAMP /sasdata/copydata/ find /sasdata/copydata -type f ! -newer /sasdata/copydata/ -print > output3.txt awk '{print "scp ... (6 Replies)
Discussion started by: tushar_spatil
6 Replies

4. Shell Programming and Scripting

For loop with dashes in filenames causing weird output

Hi again, What i'm trying to accomplish here is search a large directory for certain filesames, read from a txt file and looping through it. For instance, one of my target names from the loop file is: 1ad55f47-c342-496b-a46d-ba7de0f1b434 My loop is constructed thusly, run in a directory... (2 Replies)
Discussion started by: Karunamon
2 Replies

5. Shell Programming and Scripting

Removing columns with dashes

My files look like this I need to remove the columns where dashes are the majority, if any of the sequences has any character in that particular position it should be removed too. The IDs and Freqs should be kept intact. Thus, the resulting file should look like this Thanks in advance (14 Replies)
Discussion started by: Xterra
14 Replies

6. Forum Support Area for Unregistered Users & Account Problems

Search throws a wobbly

Dear Administrator, Rule No.5 for unregistered users is impossible to comply with because Google search thinks that any Unix command that I search for is an attack from a virus and blocks the search. I managed to find this site from an external search, and it looks really useful. Do you... (2 Replies)
Discussion started by: Ken N
2 Replies

7. Shell Programming and Scripting

AWK script to omit top characters with dashes

Hi I have an AWK script that takes an input file and outputs it as CSV format. The problem is its also outputting the characters at the top which are dashes(-------) and i want it to leave them out. My script is as follows. BEGIN { count=1; } /^/ { count+=1 if ( count > 2 ){... (3 Replies)
Discussion started by: magikminox
3 Replies

8. UNIX for Dummies Questions & Answers

double dashes

function date_diff { integer _dt1=$(date_to_num ${1:?}) integer _dt2=$(date_to_num ${2:?}) integer _ndt=0 if ] then ((_ndt=_dt2-_dt1)) fi print -- $_ndt } What does double dash '--' indicate ? Can anyone please answer this (2 Replies)
Discussion started by: systemsb
2 Replies

9. UNIX for Dummies Questions & Answers

help removing dashes from social security number

I have a file containing social security numbers with the format ###-##-####. I need to read each record in this file, reformat the SSN to the format #########, and write the record with the reformatted SSN to a new file. I am a UNIX newbie. I think I need to use either the sed or awk commands, but... (2 Replies)
Discussion started by: Marcia P
2 Replies
Login or Register to Ask a Question