How to use grep to match lines where the first character falls in a range?

26,251

Because you have used the * (zero or more) quantifier, your expression is going to match every line. Change it to

grep -i "^[a-c]" data.txt

and it should work as you intend.

Share:
26,251

Related videos on Youtube

AJJ
Author by

AJJ

Updated on September 18, 2022

Comments

  • AJJ
    AJJ over 1 year

    I am trying to grep lines where the first character is an A, B, or C.

    I am trying this:

    grep -i "^[a-c]*" data.txt

    I want it to only care about the very first character, the rest of the line I don't care about.

  • muru
    muru over 6 years