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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for byte position of a string within a file

Status
Not open for further replies.

eholdo

Technical User
May 30, 2002
31
US
need to find a way to return the byte position of a string within a file. csh method is needed.
Thanks!
 
Try nawk

Code:
nawk 'BEGIN {bytepos=0}{sumlinebytes+=length($0);strpos=match($0,"[COLOR=red]yourstring[/color]");if (strpos) {bytepos=sumlinebytes+strpos-length($0);exit} } END {print bytepos}' [COLOR=red]yourfile[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top