-1

ファイルからすべてのドライバーを一覧表示したい/etc/X11/xorg.conf

私のファイルは次のようになります。

section "input class"
        identifier    "blablabla"
        driver        "my driver here"

正規表現を使用して、このファイル内のすべてのドライバーを一覧表示したいと考えています。私はこのようなものを使用できると思いました:grep -i "driver"そしてそれをパイプと連結してから、間にあるものを見つけます""

しかし、これは機能していませんgrep -i "driver" | grep -i "\"(.*?)\""

問題は空白だと思いますが、[[:space:]]それらを無視するにはどうすればよいですか?

助けてくれてありがとう!

4

1 に答える 1

1

Not the best solution, but something that I can quickly think of:

grep driver /etc/X11/xorg.conf  | cut -d '"'  -f 2

The grep command would list all lines containing the pattern driver. The -d argument to cut specifies the delimiter, and the -f specifies the fields you want to print

You could do the same using awk in a single command:

awk -F '"' -v PATTERN="driver" '$0 ~ PATTERN { print $2 }' /etc/X11/xorg.conf
于 2013-03-16T06:28:16.297 に答える