Skip to content

Instantly share code, notes, and snippets.

@yi
Created February 11, 2016 06:29
Show Gist options
  • Save yi/f7546afa5e63c706d944 to your computer and use it in GitHub Desktop.
Save yi/f7546afa5e63c706d944 to your computer and use it in GitHub Desktop.
常用的unix指令集合

在长文本中显示指定的行号的行内容

Example 1: Display specific lines (based on line number) of a file using sed command

View only the specific lines mentioned by line numbers.

Syntax:

$ sed -n -e Xp -e Yp FILENAME

sed : sed command, which will print all the lines by default. -n : Suppresses output. -e CMD : Command to be executed Xp: Print line number X Yp: Print line number Y FILENAME : name of the file to be processed. The example mentioned below will print the lines 120, 145, 1050 from the syslog.

$ sed -n -e 120p -e 145p -e 1050p /var/log/syslog In the following example, you can view the content of var/log/cron from line number 101 to 110.

M – Starting line number N – Ending line number

Syntax: sed -n M,Np FILENAME

$ sed -n 101,110p /var/log/cron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment