Skip to content

Instantly share code, notes, and snippets.

@honwhy
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save honwhy/d7aecec03c3e22012f64 to your computer and use it in GitHub Desktop.

Select an option

Save honwhy/d7aecec03c3e22012f64 to your computer and use it in GitHub Desktop.
use regular expression in sed command
#!/bin/bash
# 在Linux终端使用sed命令,使用正则表达式时+没有被当作元字符
# 1. 使用如下命令
sed -i '/^[0-9]+/d' some.txt
cat some.txt
# 并不能够将数字开头的行删除
# 2. 使用如下命令
sed -i '/^[0-9]\+/d' some.txt
#就可以满足刚才的需求了
cat some.txt
@honwhy
Copy link
Author

honwhy commented Aug 9, 2014

参考 sed metacharacters文档
http://www.cuyamaca.net/gainswor/schedule_532_files/SED_metacharacters.pdf
这里并没有发现+的写法,但是又{m,n}量词写法,都需要\转义。

@honwhy
Copy link
Author

honwhy commented Aug 9, 2014

sed和awk命令文档,来自美帝某大学?
http://www.cs.umsl.edu/~sanjiv/classes/cs2750/lectures/re.pdf

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