bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep


From: Alain Magloire
Subject: Re: grep
Date: Sun, 13 May 2001 00:38:27 -0400 (EDT)

Bonjour

> Hello.  My name is Bryan Sillman, from the company "Standard Internet"
> 
> I saw your e-mail address in the man pages (we have it installed on a Linux 
> box) and wanted to drop you a line about a problem I have.
> 
> I trying to use grep to find the exact byte position of a string in a file.
> 
> On a shell, I have a file called TEST.  In TEST, I have one line:
>       ABCDE
> 
> And I tried to execute the command
> grep -b D TEST
> 
> Which translate to:
>    Grep command, Byte Offset Switch, Data Searched and File
> 
> When I run it, it returns:
> address@hidden bid]# grep -b D TEST
> 0:ABCDE
> 
> Shouldn't this return the number "4", because "D" is the fourth byte in the 
> file?

It is the offset of the begining of the line where the match was found.
So if you have:
# cat -n TEST
     1  ABCDEF
     2  ABCDEF
     3  ABCDEF
     4  ABCDEF
     5  ABCDEF
# grep -b D TEST
0:ABCDEF
7:ABCDEF
14:ABCDEF
21:ABCDEF
28:ABCDEF

Also do not forget that each lines contains a Newline:
0 1 2 3 4 5   6
A B C D E F '\n'

I can agree that the documentation could be better and the name of
the option is not intuitive.

I'll make a note of it.

--
alain




reply via email to

[Prev in Thread] Current Thread [Next in Thread]