本篇主要写一些shell脚本文本处理工具sed的使用。


概述

sed(Stream EDitor)是一个强大而简单的文本解析转换工具,可以读取文本,并根据指定的条件对文本内容进行编辑(删除、替换、添加、移动等),最后输出所有行或者仅输出处理的某些行。

sed也可以在无交互的情况下实现相复杂的文本处理操作,被广泛应用于Shell脚本中,用以完成各种自动化处理任务。

sed的工作流程主要包括读取、执行和显示三个过程:

  • 读取:sed从输入流(文件、管道、标准输入)中读取一行内容并存储到临时的缓冲区中(又称模式空间,pattern space
  • 执行:默认情况下,所有的sed命令都在模式空间中顺序地执行,除非指定了行的地址,否则 sed命令将会在所有的行上依次执行
  • 显示:发送修改后的内容到输出流。再发送数据后,模式空间将会被清空

在所有的文件内容都被处理完成之前,上述过程将重复执行,直至所有内容被处理完。

默认情况下,所有的sed命令都是在模式空间内执行的,因此输入的文件并不会发生任何变化,除非是用重定向存储输出。

命令常见用法

  • 命令有两种格式:
sed [选项] '编辑指令' 文件1 文件2...
sed [选项] -f 脚本文件 文件1 文件2...
  • 常见的命令选项

-e--expression=:表示用指定命令或者脚本来处理输入的文本文件

-f--file=:表示用指定的脚本文件来处理输入的文本文件

-h--help:显示帮助

-n--quietsilent:表示仅显示处理后的结果

-i:直接编辑文本文件

  • 操作

通常情况下是采用的[n1[,n2]]操作参数的格式。

a:增加,在当前行下面增加一行指定内容

c:替换,将选定行替换为指定内容

d:删除,删除选定的行

i:插入,在选定行上面插入一行指定内容

p:打印,如果同时指定行,表示打印指定行;如果不指定行,则表示打印所有内容;如果有非打印字符,则以ASCII码输出。其通常与-n选项一起使用

s:替换,替换指定字符

y:字符转换

示例

输出符合条件的文本“p”

  • 输出所有内容,等同于cat test.txt
[root@localhost ~]# sed -n 'p' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 输出第3
[root@localhost ~]# sed -n '3p' test.txt
The home of Football on BBC Sport online.
  • 输出3~5
[root@localhost ~]# sed -n '3,5p' test.txt
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
  • 输出所有奇数行,n表示读入下一行资料
[root@localhost ~]# sed -n 'p;n' test.txt
he was short and fat.
The home of Football on BBC Sport online.
google is the best tools for search keyword.
PI=3.141592653589793238462643383249901429
Actions speak louder than words #woooooood #
I bet this place is really spooky late at night!
I shouldn't have lett so tast.
  • 输出所有偶数行,n表示读入下一行资料
[root@localhost ~]# sed -n 'n;p' test.txt
He was wearing a blue polo shirt with black pants.
the tongue is boneless but it breaks bones.12!
The year ahead will test our political establishment to the limit.
a wood cross! #woood #
AxyzxyzxyzxyzC
Misfortunes never come alone/single.
  • 输出第1~5行之间的奇数行(1,3,5)
[root@localhost ~]# sed -n '1,5{n;p}' test.txt
He was wearing a blue polo shirt with black pants.
the tongue is boneless but it breaks bones.12!
The year ahead will test our political establishment to the limit.
  • 输出第10行至文件尾之间的偶数行(11,13,15)
[root@localhost ~]# sed -n '10,${n;p}' test.txt 

#woooooood #
I bet this place is really spooky late at night!
I shouldn't have lett so tast.

sed命令结合正则表达式时,格式略有不同,正则表达式以/包围。

  • 输出包含the的行
[root@localhost ~]# sed -n '/the/p' test.txt
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
  • 输出从第4行至第一个包含the的行
[root@localhost ~]# sed -n '4,/the/p' test.txt
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
  • 输出包含the的行所在的行号,等号=用来输出行号
[root@localhost ~]# sed -n '/the/=' test.txt
4
5
6
  • 输出以PI开头的行
[root@localhost ~]# sed -n '/^PI/p' test.txt
PI=3.141592653589793238462643383249901429
  • 输出以数字结尾的行
[root@localhost ~]# sed -n '/[0-9]$/p' test.txt
PI=3.141592653589793238462643383249901429
  • 输出包含单词wood 的行,\<\>代表单词边界
[root@localhost ~]# sed -n '/\<wood\>/p' test.txt
a wood cross!

删除符合条件的文本“d”

nl命令用来计算文件的行数

  • 删除第3
[root@localhost ~]# nl test.txt | sed '3d'
1 he was short and fat.
2 He was wearing a blue polo shirt with black pants.
4 the tongue is boneless but it breaks bones.12!
5 google is the best tools for search keyword.
6 The year ahead will test our political establishment to the limit.
7 PI=3.141592653589793238462643383249901429
8 a wood cross!
9 Actions speak louder than words 10 #woood #
11 #woooooood #
12 AxyzxyzxyzxyzC
13 I bet this place is really spooky late at night!
14 Misfortunes never come alone/single.
15 I shouldn't have lett so tast.
  • 删除第3~5
[root@localhost ~]# nl test.txt | sed '3,5d'
1 he was short and fat.
2 He was wearing a blue polo shirt with black pants.
6 The year ahead will test our political establishment to the limit.
7 PI=3.141592653589793238462643383249901429
8 a wood cross!
9 Actions speak louder than words 10 #woood #
11 #woooooood #
12 AxyzxyzxyzxyzC
13 I bet this place is really spooky late at night!
14 Misfortunes never come alone/single.
15 I shouldn't have lett so tast.
  • 删除包含cross的行,原本的第8行被删除
[root@localhost ~]# nl test.txt | sed '/cross/d'
1 he was short and fat.
2 He was wearing a blue polo shirt with black pants.
3 The home of Football on BBC Sport online.
4 the tongue is boneless but it breaks bones.12!
5 google is the best tools for search keyword.
6 The year ahead will test our political establishment to the limit.
7 PI=3.141592653589793238462643383249901429
9 Actions speak louder than words 10 #woood #
11 #woooooood #
12 AxyzxyzxyzxyzC
13 I bet this place is really spooky late at night!
14 Misfortunes never come alone/single.
15 I shouldn't have lett so tast.
  • 删除不包含cross的行,用!符号表示取反操作
[root@localhost ~]# nl test.txt | sed '/cross/!d'
8 a wood cross!
  • 删除以小写字母开头的行
[root@localhost ~]# sed '/^[a-z]/d' test.txt
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 删除以.结尾的行
[root@localhost ~]# sed '/\.$/d' test.txt
the tongue is boneless but it breaks bones.12!
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
  • 删除所有空行
[root@localhost ~]# sed '/^$/d' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words
#woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 删除重复的空行,即连续空行只保留一个
[root@localhost ~]# sed '/^$/{n;/^$/d}' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
[root@localhost ~]# cat -s test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.

替换符合条件的文本

s(字符串替换)

c(整行/整块替换)

y(字符转换)

  • 将每行中的第一个the替换为THE
[root@localhost ~]# sed 's/the/THE/' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
THE tongue is boneless but it breaks bones.12!
google is THE best tools for search keyword.
The year ahead will test our political establishment to THE limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 将每行中的第3l替换为L
[root@localhost ~]# sed 's/l/L/3' test.txt
he was short and fat.
He was wearing a blue polo shirt with bLack pants.
The home of Football on BBC Sport onLine.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our poLitical establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is realLy spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 将文件中的所有the替换为THE
[root@localhost ~]# sed 's/the/THE/g' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
THE tongue is boneless but it breaks bones.12!
google is THE best tools for search keyword.
The year ahead will test our political establishment to THE limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 将文件中的所有o删除(替换为空串)
[root@localhost ~]# sed 's/o//g' test.txt
he was shrt and fat.
He was wearing a blue pl shirt with black pants.
The hme f Ftball n BBC Sprt nline.
the tngue is bneless but it breaks bnes.12!
ggle is the best tls fr search keywrd.
The year ahead will test ur plitical establishment t the limit.
PI=3.141592653589793238462643383249901429
a wd crss!
Actins speak luder than wrds #wd #
#wd #
AxyzxyzxyzxyzC
I bet this place is really spky late at night!
Misfrtunes never cme alne/single.
I shuldn't have lett s tast.
  • 在每行行首插入#
[root@localhost ~]# sed 's/^/#/' test.txt
#he was short and fat.
#He was wearing a blue polo shirt with black pants.
#The home of Football on BBC Sport online.
#the tongue is boneless but it breaks bones.12!
#google is the best tools for search keyword.
#The year ahead will test our political establishment to the limit.
#PI=3.141592653589793238462643383249901429
#a wood cross!
#Actions speak louder than words
#
#
##woood #
##woooooood #
#AxyzxyzxyzxyzC
#I bet this place is really spooky late at night!
#Misfortunes never come alone/single.
#I shouldn't have lett so tast.
  • 在包含the的每行行首插入#号
[root@localhost ~]# sed '/the/s/^/#/' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
#the tongue is boneless but it breaks bones.12!
#google is the best tools for search keyword.
#The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 在每行行尾插入字符串EOF
[root@localhost ~]# sed 's/$/EOF/' test.txt
he was short and fat.EOF
He was wearing a blue polo shirt with black pants.EOF
The home of Football on BBC Sport online.EOF
the tongue is boneless but it breaks bones.12!EOF
google is the best tools for search keyword.EOF
The year ahead will test our political establishment to the limit.EOF
PI=3.141592653589793238462643383249901429EOF
a wood cross!EOF
Actions speak louder than wordsEOF
EOF
EOF
#woood #EOF
#woooooood #EOF
AxyzxyzxyzxyzCEOF
I bet this place is really spooky late at night!EOF
Misfortunes never come alone/single.EOF
I shouldn't have lett so tast.EOF
  • 将第3~5行中的所有the替换为THE
[root@localhost ~]# sed '3,5s/the/THE/g' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
THE tongue is boneless but it breaks bones.12!
google is THE best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 将包含the的所有行中的o都替换为O
[root@localhost ~]# sed '/the/s/o/O/g' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tOngue is bOneless but it breaks bOnes.12!
gOOgle is the best tOOls fOr search keywOrd.
The year ahead will test Our pOlitical establishment tO the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.

迁移符合条件的文本

H(复制到剪贴板)

g、G(将剪贴板中的数据覆盖/追加至指定行)

w(保存为文件)

r(读取指定文件)

a(追加指定内容)

  • 将包含the的行迁移至文件末尾,{;}用于多个操作
[root@localhost ~]# sed '/the/{H;d};$G' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast. the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
  • 将第1~5行内容转移至第17行后
[root@localhost ~]# sed '1,5{H;d};17G' test.txt
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast. he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
  • 将包含the的行另存为文件out.file
[root@localhost ~]# sed '/the/w out.file' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
[root@localhost ~]# cat out.file
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
  • 将文件/etc/hostname的内容添加到包含the的每行以后
[root@localhost ~]# sed '/the/r /etc/hostname' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
localhost.localdomain
google is the best tools for search keyword.
localhost.localdomain
The year ahead will test our political establishment to the limit.
localhost.localdomain
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 在第3行后插入一个新行,内容为New
[root@localhost ~]# sed '3aNew' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
New
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 在包含the的每行后插入一个新行,内容为New
[root@localhost ~]# sed '/the/aNew' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
New
google is the best tools for search keyword.
New
The year ahead will test our political establishment to the limit.
New
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.
  • 在第3行后插入多行内容,中间的\n表示换行
[root@localhost ~]# sed '3aNew1\nNew2' test.txt
he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
New1
New2
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast.

使用脚本编辑文件

将多个编辑指令存放到文件中(每行一条编辑指令),通过-f选项来调用

  • 将第1~5行内容转移至第17行后,以上操作可以改用脚本文件方式:
[root@localhost ~]# vim opt.list
1,5H
1,5d
17G
[root@localhost ~]# sed -f opt.list test.txt
The year ahead will test our political establishment to the limit.
PI=3.141592653589793238462643383249901429
a wood cross!
Actions speak louder than words #woood #
#woooooood #
AxyzxyzxyzxyzC
I bet this place is really spooky late at night!
Misfortunes never come alone/single.
I shouldn't have lett so tast. he was short and fat.
He was wearing a blue polo shirt with black pants.
The home of Football on BBC Sport online.
the tongue is boneless but it breaks bones.12!
google is the best tools for search keyword.

直接操作文件示例

#!/bin/bash
# 指定样本文件路径、配置文件路径
SAMPLE="/usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/vsftpd.conf"
CONFIG="/etc/vsftpd/vsftpd.conf"
# 备份原来的配置文件,检测文件名为/etc/vsftpd/vsftpd.conf.bak 备份文件是否存在, 若不存在则使用 cp 命令进行文件备份
[ ! -e "$CONFIG.bak" ] && cp $CONFIG $CONFIG.bak
# 基于样本配置进行调整,覆盖现有文件
sed -e '/^anonymous_enable/s/YES/NO/g' $SAMPLE > $CONFIG
sed -i -e '/^local_enable/s/NO/YES/g' -e '/^write_enable/s/NO/YES/g' $CONFIG
grep "listen" $CONFIG || sed -i '$alisten=YES' $CONFIG
# 启动vsftpd 服务,并设为开机后自动运行
systemctl restart vsftpd
systemctl enable vsftpd

Shell 编程 文本处理工具 sed的更多相关文章

  1. 文本处理工具sed

    处理文本的工具sed  行编辑器 ,默认自带循环. sed是一种流编辑器,它一次处理一行内容. 功能:主要用来自动编辑一个或多个文件,简化对文件的反复操作,编写转换程序等 sed工具 用法: sed ...

  2. Linux Shell编程第4章——sed和awk

    目录 sed命令基本用法 sed命令实例 命令选项 文本定位 编辑命令 awk编程模型 awk编程实例 1.awk模式匹配 2.记录和域 3.关系和布尔运算符 4.表达式 5.系统变量 6.格式化输出 ...

  3. shell编程学习笔记之sed编辑器

    在shell编程中,大多数处理的都是文本文件.对文本文件进行处理除了使用交互式文本编辑器(vi[m],gedit......)也可以使用另外一类:流编辑器. 流编辑器:使用预定义的编辑规则来对文本进行 ...

  4. Linux文本处理工具——Sed

    sed:数据流编辑器: awk:报告文本的生成器 sed 基本用法:(Stream EDitor) Stream 流 EDitor 编辑器 行编辑器 全屏编辑器:vi/vimsed:内存空间(模式空间 ...

  5. 4.shell编程-文本处理三剑客之sed

    4.1.sed的选项 sed,流编辑器.对标准输出或文件进行逐行处理. 语法格式 第一种:stdout | sed [option] "pattern command" 第二种:s ...

  6. 文本处理工具——sed基础

    一sed介绍 三剑客是grep,sed,awk,功能都很强大. 其中sed是Stream EDitor,流编辑器 行,编辑器的简写,它一次处理一行内容. sed的强大在于可以对文件进行修改,很适合在脚 ...

  7. 简单介绍shell编程四剑客之sed

    概要:分别的作用 grep:文本过滤(模式:pattern)工具,grep,egrep,fgrep,擅长过滤. sed:stream editor 文本编辑工具:(流编辑器),擅长取行.替换. awk ...

  8. linux笔记:shell编程-文本处理命令

    cut(字段提取命令,也叫列提取命令): printf(格式化输出命令): awk(awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理): sed(sed是一个很好 ...

  9. 文本处理工具——sed进阶

    一sed的搜索替代 (一)常见的和替代相关的选项 搜索替代,和vim的写法很像 s///:查找替换,支持使用其它分隔符,s@@@,s### p: 显示替换成功的行,就是打印. w /PATH/TO/S ...

随机推荐

  1. 如何用node编写命令行工具,附上一个ginit示例,并推荐好用的命令行工具

    原文 手把手教你写一个 Node.js CLI 强大的 Node.js 除了能写传统的 Web 应用,其实还有更广泛的用途.微服务.REST API.各种工具……甚至还能开发物联网和桌面应用.Java ...

  2. [LeetCode] 730. Count Different Palindromic Subsequences 计数不同的回文子序列的个数

    Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...

  3. 命令行编译带外部包依赖的java源文件 [以JDBC MySQL8为例]

    环境: MySQL8 JDK11(SE) 首先下载MySQL8的JDBC驱动 https://dev.mysql.com/downloads/connector/j/选 PlatForm Indepe ...

  4. 使用阿里云OSS上传文件

    本文介绍如何利用Java API操作阿里云OSS对象存储. 1.控制台操作 首先介绍一下阿里云OSS对象存储的一些基本概念. 1.1 进入对象存储界面 登录阿里云账号,进入对象存储界面,如图所示. 进 ...

  5. oracle--10.2.0.3升级到11.2.0.4

    一,环境 01,待升级的系统 升级仅支持10.2.0.2版本之后的系统,如果不是,请把10G升级至高版本! 本次实验环境10.2.0.3 02,挂载11G系统 03,升级须知 1) 做好备份 二,DB ...

  6. 表单只有一项 input 时按回车键会提交表单

    在 Vue 中 使用 Element UI,使用表单  el-form 只有一个  el-input  项,使用  @keyup.enter.native 来处理回车事件. 结果发现按下回车时页面总会 ...

  7. 动手学深度学习6-认识Fashion_MNIST图像数据集

    获取数据集 读取小批量样本 小结 本节将使用torchvision包,它是服务于pytorch深度学习框架的,主要用来构建计算机视觉模型. torchvision主要由以下几个部分构成: torchv ...

  8. torch_09_DCGAN_注意的细节

    DCGAN github链接:https://github.com/darr/DCGAN DCGAN:1.在一次epoch中,如果第i批的i能够整除every_print,则打印到output文件中( ...

  9. Navicat MYSQL 建立关联表 保存时遇到 cannot add foreign key constraint

    首先建立user表,如下图 然后建立message表,userid用作外键,关联user表的id 点击上面的外键按钮,添加外键如下 结果保存时报错: cannot add foreign key co ...

  10. WPF Properties中Settings使用方式

    Settings位于Properties中 代码上看Setting是一个单例模式 其中可以编写属性,方法 因为Setting位于窗口类之前实例化,所以通常用来窗口的某些设置,绑定. --------- ...