- 浏览: 266072 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
di1984HIT:
这个是默认的。!
ElasticSearch (3) Java API -- put mapping to index -
di1984HIT:
谢谢,学习了~~~
ElasticSearch (3) Java API -- put mapping to index -
di1984HIT:
写的很好,谢谢啦
ElasticSearch (3) Java API -- put mapping to index -
swzzm:
.............文件加密了,密码了
Hive + Hbase
The `s’ command is probably the most important in `sed’ and has a lot of different options.
The `s’ command attempts to match the pattern space against the supplied REGEXP; if the match is successful, then that portion of the pattern space which was matched is replaced with REPLACEMENT.
Syntax:
#sed 'ADDRESSs/REGEXP/REPLACEMENT/FLAGS' filename
#sed 'PATTERNs/REGEXP/REPLACEMENT/FLAGS' filename
s is substitute command
/ is a delimiter
REGEXP is regular expression to match
REPLACEMENT is a value to replace
LAGS can be any of the following
g Replace all the instance of REGEXP with REPLACEMENT
n Could be any number,replace nth instance of the REGEXP with REPLACEMENT.
p If substitution was made, then prints the new pattern space.
i match REGEXP in a case-insensitive manner.
w file If substitution was made, write out the result to the given file.
We can use different delimiters ( one of @ % ; : ) instead of /
建立测试文件
$ cat thegeekstuff.txt
# Instruction Guides
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子1:用Linux-Unix替换Linux
$ sed 's/Linux/Linux-Unix/' thegeekstuff.txt
# Instruction Guides
1. Linux-Unix Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux-Unix
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子2:用s//g替换所有
$ sed 's/Linux/Linux-Unix/g' thegeekstuff.txt
# Instruction Guides
1. Linux-Unix Sysadmin, Linux-Unix Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux-Unix
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子3:用s//2只替换第二个单词
$ sed 's/Linux/Linux-Unix/2' thegeekstuff.txt
# Instruction Guides
1. Linux Sysadmin, Linux-Unix Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子4:用s//gpw替换所有单词并打印和写入文件
$ sed -n 's/Linux/Linux-Unix/gpw output' thegeekstuff.txt
1. Linux-Unix Sysadmin, Linux-Unix Scripting etc.
4. Storage in Linux-Unix
$ cat output
1. Linux-Unix Sysadmin, Linux-Unix Scripting etc.
4. Storage in Linux-Unix
例子5:模式匹配替换
$ sed '/\-/s/\-.*//g' thegeekstuff.txt
# Instruction Guides
1. Linux Sysadmin, Linux Scripting etc.
2. Databases
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows
例子6:删除每行的最后几个字母
$ sed 's/...$//' thegeekstuff.txt
# Instruction Gui
1. Linux Sysadmin, Linux Scripting e
2. Databases - Oracle, mySQL e
3. Security (Firewall, Network, Online Security e
4. Storage in Li
5. Productivity (Too many technologies to explore, not much time availab
# Additional F
6. Windows- Sysadmin, reboot e
例子7:删除所有注释行
$ sed -e 's/#.*//' thegeekstuff.txt
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
6. Windows- Sysadmin, reboot etc.
例子8:删除所有注释行和空行
$ sed -e 's/#.*//;/^$/d' thegeekstuff.txt
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
6. Windows- Sysadmin, reboot etc.
例子9:Dos到unix格式转换
Copy the DOS file to Unix, you could find \r\n in the end of each line.
This example converts the DOS file format to Unix file format using sed command.
$sed 's/.$//' filename
例子10:移除html标签(有待商榷)
In this example, the regular expression given in the sed command matches the html tags and replaces with the empty.
$ sed -e 's/<[^>]*>//g'
This <b> is </b> an <i>example</i>.
This is an example.
The `s’ command attempts to match the pattern space against the supplied REGEXP; if the match is successful, then that portion of the pattern space which was matched is replaced with REPLACEMENT.
Syntax:
#sed 'ADDRESSs/REGEXP/REPLACEMENT/FLAGS' filename
#sed 'PATTERNs/REGEXP/REPLACEMENT/FLAGS' filename
s is substitute command
/ is a delimiter
REGEXP is regular expression to match
REPLACEMENT is a value to replace
LAGS can be any of the following
g Replace all the instance of REGEXP with REPLACEMENT
n Could be any number,replace nth instance of the REGEXP with REPLACEMENT.
p If substitution was made, then prints the new pattern space.
i match REGEXP in a case-insensitive manner.
w file If substitution was made, write out the result to the given file.
We can use different delimiters ( one of @ % ; : ) instead of /
建立测试文件
$ cat thegeekstuff.txt
# Instruction Guides
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子1:用Linux-Unix替换Linux
$ sed 's/Linux/Linux-Unix/' thegeekstuff.txt
# Instruction Guides
1. Linux-Unix Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux-Unix
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子2:用s//g替换所有
$ sed 's/Linux/Linux-Unix/g' thegeekstuff.txt
# Instruction Guides
1. Linux-Unix Sysadmin, Linux-Unix Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux-Unix
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子3:用s//2只替换第二个单词
$ sed 's/Linux/Linux-Unix/2' thegeekstuff.txt
# Instruction Guides
1. Linux Sysadmin, Linux-Unix Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows- Sysadmin, reboot etc.
例子4:用s//gpw替换所有单词并打印和写入文件
$ sed -n 's/Linux/Linux-Unix/gpw output' thegeekstuff.txt
1. Linux-Unix Sysadmin, Linux-Unix Scripting etc.
4. Storage in Linux-Unix
$ cat output
1. Linux-Unix Sysadmin, Linux-Unix Scripting etc.
4. Storage in Linux-Unix
例子5:模式匹配替换
$ sed '/\-/s/\-.*//g' thegeekstuff.txt
# Instruction Guides
1. Linux Sysadmin, Linux Scripting etc.
2. Databases
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
# Additional FAQS
6. Windows
例子6:删除每行的最后几个字母
$ sed 's/...$//' thegeekstuff.txt
# Instruction Gui
1. Linux Sysadmin, Linux Scripting e
2. Databases - Oracle, mySQL e
3. Security (Firewall, Network, Online Security e
4. Storage in Li
5. Productivity (Too many technologies to explore, not much time availab
# Additional F
6. Windows- Sysadmin, reboot e
例子7:删除所有注释行
$ sed -e 's/#.*//' thegeekstuff.txt
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
6. Windows- Sysadmin, reboot etc.
例子8:删除所有注释行和空行
$ sed -e 's/#.*//;/^$/d' thegeekstuff.txt
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
6. Windows- Sysadmin, reboot etc.
例子9:Dos到unix格式转换
Copy the DOS file to Unix, you could find \r\n in the end of each line.
This example converts the DOS file format to Unix file format using sed command.
$sed 's/.$//' filename
例子10:移除html标签(有待商榷)
In this example, the regular expression given in the sed command matches the html tags and replaces with the empty.
$ sed -e 's/<[^>]*>//g'
This <b> is </b> an <i>example</i>.
This is an example.
发表评论
-
Linux File descriptor limit
2012-11-01 13:38 30981. Find out what the current op ... -
grep 实用例子
2012-07-13 16:00 1574首先创建示例文件 $ cat demo_file THIS L ... -
sed系列:文件多行操作
2012-06-26 12:51 3449Sed reads line by line, removes ... -
sed系列:多命令执行
2012-06-22 17:01 5010Syntax: #sed -e 'command' -e 'c ... -
sed系列:行或者模式匹配删除特定行
2012-06-21 15:52 98487“p” command prints the buffer ( ... -
sed系列:用地址或者模式匹配输出文件行
2012-06-21 15:02 3567Unix Sed Introduction sed is a ... -
sed 系列: 分支操作
2012-06-21 11:47 1523无条件分支语法 $ sed ':label command(s ... -
sed 系列: 怎样用sed写文件
2012-06-19 20:24 2375In this article, let us review ... -
sed tool basic
2012-06-19 20:12 973语法 sed [options] '{command}' [f ... -
SSH password less login
2012-04-25 20:15 795http://www.thegeekstuff.com/200 ... -
Add environment variables for all users
2012-02-09 11:51 885/etc/profile example export ... -
Hadoop Cluster Setup
2012-01-13 16:11 433http://ankitasblogger.blogspot. ... -
linux下查找文件内容
2012-01-13 13:30 784#> find . -type f -exec gre ... -
FTP
2012-01-12 15:58 1003简单上传下载实例(/*.... ... -
CDH3
2012-01-05 11:46 1174CDH3 book O'Reilly's 'Hadoop ... -
Best Linux Books
2012-01-03 15:56 1387http://www.linuxlinks.com/artic ... -
Shell Command study
2012-01-03 15:25 799http://www.dedoimedo.com/comput ... -
GRUB
2012-01-03 12:22 838http://www.dedoimedo.com/comput ... -
linux 手动安装 oracle
2011-12-12 16:07 9446引用http://gohands.iteye.com/blog ... -
linux下Oracle自己启动
2011-12-12 16:03 965引用http://bbs.51cto.com/topic/th ...
相关推荐
在IT领域,文本处理是日常工作中不可或缺的一部分,而grep、sed、awk和perl这四个工具在处理文本时都广泛地使用了正则表达式。它们各自有着不同的特性和适用场景,理解它们之间的差异有助于我们更高效地进行文本操作...
此外,在日常工作中使用的工具如 grep、sed 和 awk 等也支持正则表达式的操作。 #### 三、基本概念介绍 1. **元字符**:正则表达式中的特殊字符,用于构建复杂的匹配规则。 - **`.`**:匹配任何单个字符(除了换...
在Linux Shell环境中,正则表达式常与grep、sed、awk等命令结合使用,以实现高效的数据筛选和处理。 1. 元字符:正则表达式的核心是元字符,它们具有特殊的含义。例如,`.`表示任意单个字符,`^`表示行首,`$`表示...
综上所述,这个压缩包文件合集详细地介绍了Linux环境中如何使用正则表达式进行文本匹配和处理,涵盖了正则表达式的基础知识、sed工具的使用以及grep系列命令的应用。掌握这些内容,将极大地提高你在Linux系统中处理...
正则表达式是一种在计算机科学中用于处理字符串的强大工具,它允许我们用简洁的模式来匹配、查找、替换或分析文本。"正则表达式超强打包工具"可能是指一个专门针对正则表达式操作的软件或者功能,它可以方便地集成...
- **文本处理**:在命令行工具如grep、sed、awk中,正则表达式用于快速查找、替换和提取文本。 - **编程语言支持**:许多编程语言内置了正则表达式库,如Python的`re`模块,JavaScript的`match`, `search`, `...
正则表达式是一种强大的文本处理工具,用于模式匹配和替换。它在各种编程语言和操作系统中广泛应用,如UNIX系统下的Vi编辑器、Perl、PHP、awk、sed,以及JavaScript等客户端脚本语言。正则表达式的核心在于构建匹配...
- **-r, --regexp-extended**: 使用扩展正则表达式(ERE),使得编写更复杂的匹配规则变得更加容易。 #### 地址定义 `sed`支持通过地址来指定要处理的具体内容或范围: - **空地址**:处理整个输入文本。 - **单...
1.正则表达式的定义:正则表达式(Regular Expression,简称Regex)是一种文本模式描述的方法,它使用特定的字符序列来匹配、查找、替换文本中的特定内容。 2.正则表达式的用途:常用于文本搜索、数据验证、字符串...
正则表达式是一种强大的文本处理工具,用于匹配、查找、替换和分析字符串模式。它由特殊字符和普通字符组成,可以构建出复杂且灵活的规则,以满足各种文本处理需求。"正则表达式匹配(自动转换)"指的是通过特定的...
正则表达式(Regular Expression)是一种模式匹配语言,它用于在字符串中进行查找、替换和提取特定模式的操作。在编程、数据分析、网页抓取等多个领域都有着广泛的应用。 首先,我们来理解什么是正则表达式。正则...
在实际应用中,正则表达式和词法分析经常结合使用,例如在文本处理工具(如grep、sed、awk)中,用户可以通过正则表达式指定搜索或替换的模式,而这些工具内部则会进行词法分析以处理输入。此外,在编译器和解释器的...
正则表达式是一种强大的文本处理工具,用于在文本中进行模式匹配、查找、替换和提取信息。它们在编程、数据分析、文本挖掘等多个领域都有广泛应用。本文将深入介绍正则表达式的基本概念、语法和常见操作。 正则...
总之,正则表达式是处理字符串的强大工具,无论在Shell脚本还是Python编程中,都能帮助我们高效地处理文本数据,进行查找、替换、分割等操作。理解和熟练运用正则表达式,对于提升文本处理能力至关重要。
正则表达式(Regular Expression,简称regex)是用于在文本中匹配特定模式的强大工具,广泛应用于数据...正则表达式参考文档12.mht文件中应包含更详细的语法说明、实例和使用技巧,建议下载查阅以获取完整知识体系。
标题《sed_awk正则表达式》揭示了本文内容将重点围绕sed和awk这两种流式文本编辑器的使用方法,以及如何在它们中应用正则表达式来过滤和处理文本数据。从描述来看,本文是一份比较详细的参考资料,旨在帮助读者掌握...