[root@service99 Sed]# echo "Line one" > line.txt
[root@service99 Sed]# sed 'i "Inster line"' line.txt
"Inster line"
Line one
[root@service99 Sed]# cat line.txt
Line one
[root@service99 Sed]# sed -i 'i Inster line' line.txt
[root@service99 Sed]# cat line.txt
Inster line
Line one
如果数据流有多行,而现在需要给最后一行添加数据,则可以:
[root@service99 Sed]# cat line.txt
Inster line
Line one
[root@service99 Sed]# sed '$a last line' line.txt
Inster line
Line one
last line
现在进行一个操作,个给文件第一行后面添加多行文本:
[root@service99 Sed]# cat test.info
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPV6INIT=no
USERCTL=no
IPADDR=192.168.2.99
PREFIX=24
[root@service99 Sed]# sed '1a \
This is add line 1.\
This is add line 2.\
This is add line 3.' test.info
//输出结果,没有添加-i选项所以并没有对原文修改
DEVICE=eth1
This is add line 1.
This is add line 2.
This is add line 3.
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPV6INIT=no
USERCTL=no
IPADDR=192.168.2.99
PREFIX=24
//还可以在第二行之前插入,即使用‘i’
更改行
更改行命令允许更改数据流中整行文本的内容。
[root@service99 Sed]# cat line.txt
This is line 1.
This is line 2.
This is line 3.
This is line 4.
[root@service99 Sed]# sed '3c This is change line 3.' line.txt
This is line 1.
This is line 2.
This is change line 3.
This is line 4.
在这里有一个特别的情况,需要说明一下:在更改命令中,可以使用地址范围,但其结果可能不是预期的效果。
[root@service99 Sed]# sed '2,3c \
> This 2,3 change line .' \
> line.txt
This is line 1.
This 2,3 change line .
This is line 4.
//sed编辑器没有用该文本更改两行,而是使用单一文本行替换了两行
[root@service99 Sed]# cat line.txt
This is line 1.
This is line 2.
This is line 3.
This is line 4.
[root@service99 Sed]# sed 'y/123/789/' line.txt
This is line 7.
This is line 8.
This is line 9.
This is line 4.
替换命令应用示例
sed -r 's/^.(.*).$/\1/' sed_02_test.info //删除每一行内的第一个和最后一个字符
sed -r 's/^..(.*)..$/\1/' sed_02_test.info //删除每一行内前两个字符和最后两个字符
sed -r '1s/^..(.*)..$/\1/' sed_02_test.info //删除第一行的前两个字符和最后两个字符
sed -r 's/^(.).(.*).(.$)/\1\2\3/' sed_02_test.info //删除每一行内第二个字符和倒数第二个字符
sed -r 's/^(.).(.*).(.)$/\1\2\3/' sed_02_test.info //同上,测试在进行“()”复制操作时,^$是否一定要放置在()内部,测试结果,是没有影响
sed -r 's/(^.).(.*).(.$)/\1\2\3/' sed_02_test.info
//sed -r 's/(^.).(.)*.(.$)/\1\2\3/' sed_02_test.info //错误实现,该表达式只是复制其中一个字符,并不满足需求
//可以使用s将旧的东西替换为空 s/old
sed的n指令(next)读取下一行
/*
sed命令执行时,会先进行读取数据的操作,当读取到数据后,就会按照指令进行对应的操作(比如p打印,d删除),而n指令需要进行的操作是要求sed直接去读取下一行的数据,这样论转下来,就会出现‘n;p’ 可以输出偶数行,‘p:n’可以输出奇数行
即好比一个循环,n指令表示continue命令跳出循环
*/
sed -n 'n;p' sed_test.info //输出偶数行
sed -n 'n;d' sed_test.info //删除偶数行
sed -n 'p;n' sed_test.info //输入奇数行
sed -n '$=' sed_test.info //显示最后一行的行号
sed '4,7s/^/#/' a.txt //4,7行添加注释
sed 's/^#anon/anon/' vsftpd.conf
sed 's/^#anon/anon/' /etc/vsftpd/vsftpd.conf
sed -n '/^DocumentRoot/p' /etc/httpd/conf/httpd.conf
sed -i '/^DocumentRoot/ s#".*"#"/opt/wwwroot"#' /etc/httpd/conf/httpd.conf
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000777c3290, pid=5632, tid=6656
#
# JRE version: Java(TM) SE Ru
Spring 中提供一些Aware相关de接口,BeanFactoryAware、 ApplicationContextAware、ResourceLoaderAware、ServletContextAware等等,其中最常用到de匙ApplicationContextAware.实现ApplicationContextAwaredeBean,在Bean被初始后,将会被注入 Applicati
在Java项目中,我们通常会自己写一个DateUtil类,处理日期和字符串的转换,如下所示:
public class DateUtil01 {
private SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void format(Date d
问题描述:
在实现类中的某一或某几个Override方法发生编译错误如下:
Name clash: The method put(String) of type XXXServiceImpl has the same erasure as put(String) of type XXXService but does not override it
当去掉@Over