Operating System - HP-UX
1832990 Members
2564 Online
110048 Solutions
New Discussion

grep in a particular position

 
SOLVED
Go to solution
Muktha
Frequent Advisor

grep in a particular position

Hi,
Is it possible to grep in a particular position in each line of a file.

Regards
Muktha
3 REPLIES 3
TTr
Honored Contributor

Re: grep in a particular position

And do what with it? Probably you want to use cut, such as "cut -c n1-n2...> and save it to a variable and compare it to whatever you need.
Eric SAUBIGNAC
Honored Contributor
Solution

Re: grep in a particular position

Bonjour

It depends on what you want to do with data you want to catch. A first approach could be :

egrep "^.{24}foo" --> will give you string foo beginning at 25th character.

Eric
Dennis Handly
Acclaimed Contributor

Re: grep in a particular position

>Eric: A first approach could be: egrep "^.{24}foo"

You don't need the egrep ERE hammer. grep will work fine with regular REs:
grep "^.\{24\}foo"