Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep question 2

Status
Not open for further replies.

RobJordan

MIS
Apr 3, 2001
296
US
Is there a way to make grep match the
absence of a leading character?

Here's an examle.

Say I want to find the string "bcd",
but I don't want to match zbcd, abcd
or any other leading character in front of bcd
except for a blank character or when bcd
starts at the beginning of a row, in which
case there is no character in front of bcd.

I could do grep " bcd ", but that wouldn't work
if bcd is the first word on a line.

Thanks in adavance,

Robert
Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
grep "^bcd" somefile will return this:

abcd - not found
bcde - found
bcde - not found
bbcde - not found
bcdfe - found

Bill.
 
how would I grep for a leading | or ' or " character?

for example I want to find "|abc" or "'abc" or ""abc"

I've tried \/ \' etc but that didn't seem to work.

Thank you,

Robert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
This worked for me on NetBSD 1.5.2 i386

grep \'abc <file>

Put a &quot;abcd&quot; 'abcd' and |abcd| into a test file, and just a backslash in front of the leading character (as above) worked in each case.
Matt
matt@paperlove.org
If I can help, I will.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top