1

I have a textfile called netlist.txt with the following contents:

M1      nmos1

M2      nmos2

P1      pmos1

        M3      nmos3

                M4      nmos4
                        P2      pmos2

I want to retrieve only the line which starts with a tab/space and matching all the "M" values that are indented, using regex.

In order to accomplish this I entered the following expression in bash:

egrep [:space:]*[M][0-9]+ netlist.txt

But it doesn't recognize the space. It retrieves all the lines regardless of having a space or not. Please give me some advice on this. Thanks, Pedro

  • 1
    You need to place it into a bracket expression: `[[:space:]]`. And if you want to match it one or more times, use `\+`/`+` or `{1,}` after it. – Wiktor Stribiżew Jan 28 '16 at 10:00

1 Answers1

0

You can use:

grep '^[[:blank:]]M[0-9]' file

Output:

        M3      nmos3

[[:blank:]] matches either a single space or a single tab at line start. [[:space:]] on the other hand matches space or tab or newline.

anubhava
  • 761,203
  • 64
  • 569
  • 643