分页: 1 / 1

如何用sed删除特定文件行?

发表于 : 2011-04-25 16:27
arthurchen
需要删除一个文件中行长度超过20个字符的行,请问如何用sed实现

Re: 如何用sed删除特定文件行?

发表于 : 2011-04-25 16:31
eexpress
行长度超过20个字符
/.{20,}/d

Re: 如何用sed删除特定文件行?

发表于 : 2011-04-25 16:39
tenzu
神是正则小王子 :em70

Re: 如何用sed删除特定文件行?

发表于 : 2011-04-25 21:19
arthurchen
eexpress 写了:行长度超过20个字符
/.{20,}/d
Thanks, but it doesn't work, I used sed -i -e '/.{20,}/d' file to remove the line contains more than 20 characters, is it right?
Can you please express the expression?

Re: 如何用sed删除特定文件行?

发表于 : 2011-04-25 23:47
lilydjwg
arthurchen 写了:
eexpress 写了:行长度超过20个字符
/.{20,}/d
Thanks, but it doesn't work, I used sed -i -e '/.{20,}/d' file to remove the line contains more than 20 characters, is it right?
Can you please express the expression?
这个是超过20个字节的吧?那个 {} 貌似需要转义。

Re: 如何用sed删除特定文件行?

发表于 : 2011-04-26 19:20
arthurchen
不用sed了, 换成awk 'length < 20' 输出小于20个字符的行, 貌似这样速度还快些
因为我的是文件全是英文字符,所以字节和字符个数是一样的

Re: 如何用sed删除特定文件行?

发表于 : 2011-04-26 20:31
lexdene
关注。

Re: 如何用sed删除特定文件行?

发表于 : 2011-05-08 2:22
scutdk
要用sed的话,需要 sed -i -r -e 因为使用了ERE,所以加-r选项