Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 09-14-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 31 July 2015, 4:29 PM EDT
Location: Amsterdam
Posts: 10,349
Thanks: 351
Thanked 2,744 Times in 2,453 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 Unix and Linux 09-14-2013
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 1 August 2015, 2:13 AM EDT
Location: Simplicity
Posts: 2,534
Thanks: 189
Thanked 770 Times in 697 Posts
Byte offset can be problematic in an UTF locale.
Does it work after

Code:
export LC_ALL=C

?
    #4  
Old Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 03:45 AM.