加入收藏 | 设为首页 | 会员中心 | 我要投稿 网站开发网_马鞍山站长网 (https://www.0555zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

Sed - An Introduction and Tutorial by Bruce Barnett

发布时间:2021-01-29 10:07:16 所属栏目:站长百科 来源:网络整理
导读:副标题#e# http://www.grymoire.com/unix/sed.html Quick Links - NEW table border="1" tr Sed Pattern Flags /tr tr td a href="http://www.grymoire.com/unix/Sed.html#uh-6"gt;/g?- Global/td /tr tr td a href="http://www.grymoire.com/unix/Sed.html

The "=" command prints the current line number to standard output. One way to find out the line numbers that contain a pattern is to use:

# add line numbers first,# then use grep,# then just print the number
cat -n file | grep 'PATTERN' | awk '{print $1}'

The?sed?solution is:

sed -n '/PATTERN/ =' file

Earlier I used the following to find the number of lines in a file

#!/bin/sh
lines=`wc -l file | awk '{print $1}' `

Using the "=" command can simplify this:

#!/bin/sh
lines=`sed -n '$=' file `

The "=" command only accepts one address,so if you want to print the number for a range of lines,you must use the curly braces:

#!/bin/sh
# Just print the line numbers 
sed -n '/begin/,/end/ {
=
d
}' file

Since the "=" command only prints to standard output,you cannot print the line number on the same line as the pattern. You need to edit multi-line patterns to do this.

(编辑:网站开发网_马鞍山站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!