sed一致行のみ印刷
2948 ワード
sed一致行のみ印刷
注意パラメータ-n
(1)ある行またはある行を表示する
1,10行を表示
$ sed
-n '1,10p' postgres.conf
10行目を表示
$ sed
-n '10p' postgres.conf
(2)一致する行を表示
$ sed
-n '/This/p' postgres.conf
私のテスト:
XYZ@XYZ-desktop:~$ sed -n '1,10 p' postgresql.conf
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
# name = value
#
# (The "="is optional.) Whitespace may be used. Comments are introduced with
# "#"anywhere on a line. The complete list of parameter names and allowed
XYZ@XYZ-desktop:~$ sed -n '10p' postgresql.conf
# "#"anywhere on a line. The complete list of parameter names and allowed
XYZ@XYZ-desktop:~$ sed -n '/This/p' postgresql.conf
# This file consists of lines of the form:
# This file is read on server startup and when the server receives a SIGHUP
# This is used when logging to stderr:
XYZ@XYZ-desktop:~$
次の部分はネット上から来て、上の理解に対してもっと十分です:
This table shows that the following commands are identical: sed -n '1,10 p'
sed -n '11,$ !p'
sed '1,10 !d'
sed '11,$ d'
|----------------------------------------------------------------------------------------|
著作権声明著作権所有@zhyiwww
引用ソースを明記してくださいhttp://www.blogjava.net/zhyiwww
|----------------------------------------------------------------------------------------|
注意パラメータ-n
(1)ある行またはある行を表示する
1,10行を表示
$ sed
-n '1,10p' postgres.conf
10行目を表示
$ sed
-n '10p' postgres.conf
(2)一致する行を表示
$ sed
-n '/This/p' postgres.conf
私のテスト:
XYZ@XYZ-desktop:~$ sed -n '1,10 p' postgresql.conf
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
# name = value
#
# (The "="is optional.) Whitespace may be used. Comments are introduced with
# "#"anywhere on a line. The complete list of parameter names and allowed
XYZ@XYZ-desktop:~$ sed -n '10p' postgresql.conf
# "#"anywhere on a line. The complete list of parameter names and allowed
XYZ@XYZ-desktop:~$ sed -n '/This/p' postgresql.conf
# This file consists of lines of the form:
# This file is read on server startup and when the server receives a SIGHUP
# This is used when logging to stderr:
XYZ@XYZ-desktop:~$
次の部分はネット上から来て、上の理解に対してもっと十分です:
Relations between d, p, and !
Sed Range Command Results
--------------------------------------------------------
sed -n 1,10 p Print first 10 lines
sed -n 11,$ !p Print first 10 lines
sed 1,10 !d Print first 10 lines
sed 11,$ d Print first 10 lines
--------------------------------------------------------
sed -n 1,10 !p Print last 10 lines
sed -n 11,$ p Print last 10 lines
sed 1,10 d Print last 10 lines
sed 11,$ !d Print last 10 lines
--------------------------------------------------------
sed -n 1,10 d Nothing printed
sed -n 1,10 !d Nothing printed
sed -n 11,$ d Nothing printed
sed -n 11,$ !d Nothing printed
--------------------------------------------------------
sed 1,10 p Print first 10 lines twice,
Then next 10 lines once
sed 11,$ !p Print first 10 lines twice,
Then last 10 lines once
--------------------------------------------------------
sed 1,10 !p Print first 10 lines once,
Then last 10 lines twice
sed 11,$ p Print first 10 lines once,
then last 10 lines twice
This table shows that the following commands are identical: sed -n '1,10 p'
sed -n '11,$ !p'
sed '1,10 !d'
sed '11,$ d'
|----------------------------------------------------------------------------------------|
著作権声明著作権所有@zhyiwww
引用ソースを明記してくださいhttp://www.blogjava.net/zhyiwww
|----------------------------------------------------------------------------------------|