1

For example

grep -n 'integer*2' *.f

Shows nothing.But

grep -n '*2' *.f


main.f:57:      integer*2 itime(nxmax)
main.f:605:             dxy=((xsource(is)-xobs)**2+(ysource(is)-yobs)**2)**.5
main.f:622:           chisum=chisum+diff2/uobs**2
model.f:15:      integer*2 veli(nxmax)
model.f:52:      size2=size**2
time.f:151:      integer*2 itime(nxmax)

I really do not understand this.

0

3 Answers 3

5

* is an operator, meaning "match the previous term 0 or more times". So integer*2 matches

intege2
integer2
integerr2
integerrr2
     :

none of which appear in your program. * at the beginning of an RE is meaningless (there's no previous term), so is either ignored or treated as match for a *. Escape the * to have it match an actual star:

'integer\*2'
Sign up to request clarification or add additional context in comments.

Comments

3

Your grep is using a regex. (Star is being interpreted differently than you might believe). Try

grep -F -n 'integer*2' *.f

Comments

2

Because grep is interpreting the search argument as a regular expression, in which * is meant as "zero or more of the preceding". So 'integer*2 would match intege2 as well as integerrrrr2 since * applies to the preceding r but will not match the literal integer*2.

Escape it with a backslash to interpret it as a literal * and you should get the desired matches:

grep -n 'integer\*2' *.f

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.