Grep --byte-offset not returning the offset (Grep version 2.5.1) | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Grep --byte-offset not returning the offset (Grep version 2.5.1)

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-14-2013
Subhamoy Subhamoy is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 16 September 2013, 4:24 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Grep --byte-offset not returning the offset (Grep version 2.5.1)

Hi,
I am trying to get the position of a repeated string in a line using

Code:
grep -b -o "pattern"

In my server I am using GNU grep version 2.14 and the code is working fine. However when I am deploying the same code in a different server which is using GNU grep version 2.5.1 the code is not working properly. Even though the byte offset option is available there. Any idea how to solve it.

Example:

Code:
export string="abc cat mat rat cat bat cat fat rat tat tat cat"
echo $string|grep -b -o "cat"

Expected output (and supported in grep 2.14):

Code:
4:cat
16:cat
24:cat
44:cat

But same code with grep version 2.5.1 is giving the following output:


Code:
0:cat
cat
cat
cat

Please suggest..

Last edited by Scrutinizer; 09-14-2013 at 10:13 AM.. Reason: code tags
Sponsored Links
    #2  
Old 09-14-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 23 September 2014, 6:41 AM EDT
Location: Amsterdam
Posts: 9,468
Thanks: 279
Thanked 2,389 Times in 2,141 Posts
Could it be that the 2.5.1 version is BSD grep? What is the output of

Code:
grep --version

In GNU grep 2.14 and 2.6.3 I get:

Code:
4:cat
16:cat
24:cat
44:cat


Last edited by Scrutinizer; 09-14-2013 at 10:54 AM..
Sponsored Links
    #3  
Old 09-14-2013
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 23 September 2014, 5:23 AM EDT
Location: Simplicity
Posts: 1,904
Thanks: 121
Thanked 556 Times in 504 Posts
Byte offset can be problematic in an UTF locale.
Does it work after

Code:
export LC_ALL=C

?
    #4  
Old 09-16-2013
Subhamoy Subhamoy is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 16 September 2013, 4:24 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Scrutinizer View Post
Could it be that the 2.5.1 version is BSD grep? What is the output of

Code:
grep --version

In GNU grep 2.14 and 2.6.3 I get:

Code:
4:cat
16:cat
24:cat
44:cat


-- It doesnt show anything as BSD. it shows GNU grep version 2.5.1

---------- Post updated at 01:52 PM ---------- Previous update was at 01:52 PM ----------

---------- Post updated at 01:54 PM ---------- Previous update was at 01:52 PM ----------

export LC_ALL=C ----> The grep didn't work even after applying this.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Get Compressed byte offset from .gz file chetan.c Shell Programming and Scripting 4 04-19-2012 09:37 AM
Tail with positive offset pandeesh UNIX for Dummies Questions & Answers 1 01-29-2012 06:00 AM
NTP client offset orange47 Solaris 2 10-03-2011 08:09 AM
Negative Offset DNAx86 Programming 1 05-09-2008 08:04 PM
offset - informix chunk shibz UNIX for Dummies Questions & Answers 1 01-27-2003 10:44 AM



All times are GMT -4. The time now is 08:20 AM.