- 浏览: 266080 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
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
无条件分支语法
$ sed ':label command(s) b label'
:label - specification of label.
commands - Any sed command(s)
label - Any Name for the label
b label – jumps to the label with out checking any conditions. If label is not specified, then jumps to the end of the script.
条件分支语法
$ sed ':label command(s) t label'
:label - specification of label.
commands - Any sed command(s)
label - Any Name for the label
t label – jumps to the label only if the last substitute command modified the pattern space. If label is not specified, then jumps to the end of the script.
创建示例文件
$ cat thegeekstuff.txt
Linux
Administration
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online\
Security
Productivity
Google Search\
Tips
"Web Based Time Tracking,
Web Based Todo list and
Reduce Key Stores etc"
无条件分支示例
示例1:替换整个文件的第一次匹配模式
$ sed '/Administration/{
s/Administration/Supervision/
:loop
n
b loop
}' thegeekstuff.txt
Linux
Supervision
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online\
Security
Productivity
Google Search\
Tips
"Web Based Time Tracking,
Web Based Todo list and
Reduce Key Stores etc"
In the above sed command, it just read line by line and prints the pattern space till Administration occurs.
Once Administration occurs, substitute Administration to Supervision (only single occurrence, note that no ‘g’ flag in substitution).
Once the first occurrence has been replaced, just read the remaining file content and print.
“n” is a sed command which prints the pattern space and overwrite it with next line.
Used “loop” as a label. “n” prints the current line and overwrite pattern space with the next line. b loop jumps to the :loop again. So this loop prints the remaining content of thegeekstuff.txt.
示例2:移除所遇的""陪陪模式之间的内容,在我们的文件里有三行内容
$sed -e ':loop
> $!{
> N
> /\n$/!b loop
> }
> s/\"[^\"]*\"//g' thegeekstuff.txt
Linux
Administration
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online\
Security
Productivity
Google Search\
Tips
$
示例3:移除html标签
$ cat index.html
<html><body>
<table
border=2><tr><td valign=top
align=right>1.</td>
<td>Line 1 Column 2</
td>
</table>
</body></html>
下面示例移除所遇html标签
$sed '/</{
> :loop
> s/<[^<]*>//g
> /</{
> N
> b loop
> }
> }' index.html
1.
Line 1 Column 2
Each time find a line contains ‘<’, first remove all HTML tags of that line.
If now the pattern space contains ‘<’, this implies a multi-line tag. Now repeat the following loop:
Join next line
Remove all HTML tags until no single ‘<’ exists
When no ‘<’ exists in the pattern space, we print it out and start a new cycle.
思考下面的和上面的有什么不同
$sed '/</{
> :loop
> s/<[^<]*>//g
> N
> b loop }
> ' index.html
1.
Line 1 Column 2
条件分支示例
示例1:如果一行以\结尾,那么,把它下一行的内容连接到这一行
$sed '
> :loop
> /\\$/N
> s/\\\n */ /
> t loop' thegeekstuff.txt
Linux
Administration
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online Security
Productivity
Google Search Tips
"Web Based Time Tracking,
Web Based Todo list and
Reduce Key Stores etc"
Check if the line ends with the backslash (/\\$/), if yes, read and append the next line to pattern space, and substitute the \ at the end of the line and number of spaces followed by that, with the single space.
If the substitution is success repeat the above step. The branch will be executed only if substitution is success.
Conditional branch mostly used for recursive patterns.
示例2:替换每行的开始空格为+
$sed '
> s/^ */&\n/
> :loop
> s/^\n//;s/ \n/\n+/
> t loop' thegeekstuff.txt
Linux
++++++++Administration
++++++++Scripting
++++++++++++++++Tips and Tricks
Windows
++++++++Administration
Database
++++++++Administration of Oracle
++++++++Administration of Mysql
Security
++++++++Network
+++++++++++++++++Online\
++++++++Security
Productivity
++++++++Google Search\
++++++++Tips
++++++++"Web Based Time Tracking,
++++++++Web Based Todo list and
++++++++Reduce Key Stores etc"
Seperate all the leading spaces and other characters of a line with a newline character.
Now replace space and newline with newline and +. So from right to left space will be replaced by + and newline will be moved left for one character.
At last in the beginning of the line \n will be there, so remove that new line.
$ sed ':label command(s) b label'
:label - specification of label.
commands - Any sed command(s)
label - Any Name for the label
b label – jumps to the label with out checking any conditions. If label is not specified, then jumps to the end of the script.
条件分支语法
$ sed ':label command(s) t label'
:label - specification of label.
commands - Any sed command(s)
label - Any Name for the label
t label – jumps to the label only if the last substitute command modified the pattern space. If label is not specified, then jumps to the end of the script.
创建示例文件
$ cat thegeekstuff.txt
Linux
Administration
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online\
Security
Productivity
Google Search\
Tips
"Web Based Time Tracking,
Web Based Todo list and
Reduce Key Stores etc"
无条件分支示例
示例1:替换整个文件的第一次匹配模式
$ sed '/Administration/{
s/Administration/Supervision/
:loop
n
b loop
}' thegeekstuff.txt
Linux
Supervision
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online\
Security
Productivity
Google Search\
Tips
"Web Based Time Tracking,
Web Based Todo list and
Reduce Key Stores etc"
In the above sed command, it just read line by line and prints the pattern space till Administration occurs.
Once Administration occurs, substitute Administration to Supervision (only single occurrence, note that no ‘g’ flag in substitution).
Once the first occurrence has been replaced, just read the remaining file content and print.
“n” is a sed command which prints the pattern space and overwrite it with next line.
Used “loop” as a label. “n” prints the current line and overwrite pattern space with the next line. b loop jumps to the :loop again. So this loop prints the remaining content of thegeekstuff.txt.
示例2:移除所遇的""陪陪模式之间的内容,在我们的文件里有三行内容
$sed -e ':loop
> $!{
> N
> /\n$/!b loop
> }
> s/\"[^\"]*\"//g' thegeekstuff.txt
Linux
Administration
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online\
Security
Productivity
Google Search\
Tips
$
示例3:移除html标签
$ cat index.html
<html><body>
<table
border=2><tr><td valign=top
align=right>1.</td>
<td>Line 1 Column 2</
td>
</table>
</body></html>
下面示例移除所遇html标签
$sed '/</{
> :loop
> s/<[^<]*>//g
> /</{
> N
> b loop
> }
> }' index.html
1.
Line 1 Column 2
Each time find a line contains ‘<’, first remove all HTML tags of that line.
If now the pattern space contains ‘<’, this implies a multi-line tag. Now repeat the following loop:
Join next line
Remove all HTML tags until no single ‘<’ exists
When no ‘<’ exists in the pattern space, we print it out and start a new cycle.
思考下面的和上面的有什么不同
$sed '/</{
> :loop
> s/<[^<]*>//g
> N
> b loop }
> ' index.html
1.
Line 1 Column 2
条件分支示例
示例1:如果一行以\结尾,那么,把它下一行的内容连接到这一行
$sed '
> :loop
> /\\$/N
> s/\\\n */ /
> t loop' thegeekstuff.txt
Linux
Administration
Scripting
Tips and Tricks
Windows
Administration
Database
Administration of Oracle
Administration of Mysql
Security
Network
Online Security
Productivity
Google Search Tips
"Web Based Time Tracking,
Web Based Todo list and
Reduce Key Stores etc"
Check if the line ends with the backslash (/\\$/), if yes, read and append the next line to pattern space, and substitute the \ at the end of the line and number of spaces followed by that, with the single space.
If the substitution is success repeat the above step. The branch will be executed only if substitution is success.
Conditional branch mostly used for recursive patterns.
示例2:替换每行的开始空格为+
$sed '
> s/^ */&\n/
> :loop
> s/^\n//;s/ \n/\n+/
> t loop' thegeekstuff.txt
Linux
++++++++Administration
++++++++Scripting
++++++++++++++++Tips and Tricks
Windows
++++++++Administration
Database
++++++++Administration of Oracle
++++++++Administration of Mysql
Security
++++++++Network
+++++++++++++++++Online\
++++++++Security
Productivity
++++++++Google Search\
++++++++Tips
++++++++"Web Based Time Tracking,
++++++++Web Based Todo list and
++++++++Reduce Key Stores etc"
Seperate all the leading spaces and other characters of a line with a newline character.
Now replace space and newline with newline and +. So from right to left space will be replaced by + and newline will be moved left for one character.
At last in the beginning of the line \n will be there, so remove that new line.
发表评论
-
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 3568Unix Sed Introduction sed is a ... -
sed 系列: 用正则表达式查找和替换
2012-06-19 20:55 33108The `s’ command is probably the ... -
sed 系列: 怎样用sed写文件
2012-06-19 20:24 2376In 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 ...
相关推荐
- **Sed命令语法**:sed是"stream editor"的缩写,它采用的是基于文本的流处理方式,通过一系列的命令行参数对文本数据进行过滤和转换。 - **Sed脚本执行流程**:sed的执行过程涉及读取输入、处理、输出三个阶段。它...
所有的文本处理操作(如查找、替换等)都是在此缓存中进行的。当一行数据处理完成后,该行会被输出,模式空间随之清空,并读取下一行数据继续处理,直至文件处理完毕。 #### 高级命令分类 根据提供的内容,sed 的...
sed脚本包含一系列的命令,这些命令可以对文本进行插入、删除、替换等操作。常见的命令包括s(替换)、d(删除)、p(打印)等。而sed还具有一些高级命令,通常不太常用,但在处理复杂文本任务时非常有用。 GNU sed...
sed的编辑操作基于这些空间进行,并且这些操作可以在命令行或者脚本文件中定义。 #### 二、使用sed **2.1 执行命令列上的编辑指令** 在命令行上直接使用sed进行文本编辑非常方便。例如,如果你想将文件`file.txt`...
本文将通过一系列中文实例来深入理解sed的用法。** 1. **基本语法** sed的工作方式是读取一行文本,对这一行进行处理,然后输出处理结果,再读取下一行,直到文件结束。基本语法是`sed 'command' filename`,其中`...
Sed是一个流编辑器(Stream Editor),它一次处理文本文件的一行内容,对模式空间(pattern space)中的文本执行一系列编辑操作。Sed通常用于快速编辑文件,尤其是在处理大量数据时,它不会直接修改原文件,而是将...
3. **命令**: `sed`支持一系列内置命令来进行文本处理。这些命令可以单独使用,也可以通过管道连接起来形成复杂的文本处理流程。 #### 三、sed命令详解 ##### 1. 基本命令格式 - **调用格式**: `sed [选项] '命令...
Sed的工作方式是逐行读取输入文本,将当前行放入模式空间,执行一系列命令,然后将处理结果输出。除非特别设置,原始文件不会被修改,处理结果通常会输出到标准输出。Sed主要用于自动化文本处理,例如批量替换、格式...
- **结构**:一系列命令的集合。 - **示例脚本**: ```sed /pattern/d s/old/new/g ``` #### 三、awk简介 ##### 3.1 awk概述 - **名称由来**:以其开发者Aho、Weinberger和Kernighan的名字命名。 - **主要功能...
在本文中,我们将深入探讨如何使用Shell中的`sed`命令来对配置文件进行替换操作,特别是针对与Linux、uboot和buildroot相关的配置文件。`sed`(流编辑器)是一个强大的文本处理工具,它可以对输入流(标准输入或其他...
本书《Sed and Awk 101 Hacks》面向希望提升自己在Unix/Linux系统操作能力的开发者、系统管理员、数据库管理员或IT管理员,旨在帮助读者快速掌握Sed和Awk的核心用法,并通过实例讲解如何将这些工具用于实际问题解决...
Sed的主要工作原理是逐行读取输入文件(标准输入或其他文件),将每一行复制到内部缓冲区——称为“模式空间”(Pattern Space),然后在模式空间中执行一系列预定义的命令,最后将修改后的行输出到标准输出。...
- `sed` 更适合处理单行文本,主要用于文本查找、替换、删除等简单操作。 - `awk` 更侧重于处理多行文本,尤其是具有结构化的数据处理,支持更复杂的表达式和计算。 - `sed` 不支持变量和复杂的逻辑控制,而 `awk...
它主要用于对文本文件进行非交互式的编辑,支持对文本进行查找、替换、删除等操作。`sed` 的强大之处在于它可以完美地匹配正则表达式,因此在处理复杂的文本模式匹配时非常有用。 #### 二、基本语法与选项 **基本...
更多复杂的命令和模式匹配允许sed执行查找、替换、条件分支等操作。 六、sed在shell脚本中的应用 sed的强大在于它可以无缝集成到shell脚本中,实现自动化文本处理。例如,通过管道将其他命令的输出传递给sed,或者...
- Shell脚本是包含一系列命令的文本文件,可以一次性执行多个操作。 - 脚本开头通常会指定解释器,如`#!/bin/bash`,这告诉系统使用哪个Shell来运行脚本。 3. **基本语法与命令** - 变量声明:`VARNAME=value`...
这个系统旨在提高成绩管理的效率,提供友好的用户交互界面,并实现一系列成绩处理功能。以下是具体的知识点讲解: 1. **Shell脚本编程**: - **Bash Shell**:Bash是Linux系统中的默认Shell,它是一种命令解释器,...