windows的git添加wget
下载wget:https://eternallybored.org/misc/wget/
拷贝wget
成功
正则表达式
需要转义的特殊字符
# 添加转义符改变原来的意思
# 案例:
# 第一部分
^ab 开头为ab的字符串,例如abc/abc1
ab$ 结尾为ab的字符串,例如qab/c1ab
^ab$ 开头和结尾都是ab,就是ab本身
ab. ab后面跟上一个字符,例如abc/ab1,这个点可以表示除\n(换行符)和\r(回车符)的任意字符
^a.b$ a为开头,b为结尾,中间是一个字符,例如a1b
ab* a后面跟0个及以上的b,例如a/ab/abb
ab.* ab后面跟0个及以上的字符,例如ab/abc/ab123
.*ab 表示ab为结尾,ab之前有0个及以上的字符,例如1ab/aab/1aaab
ab+a后面跟1个及以上的b,例如ab/abb
ab? a后面跟0个或者1个b,仅表示a/ab
ab\.php 表示ab.php,中间的点被反斜杠\转义了,例如ab\*表示ab*
# 第二部分
ab 表示a后面跟1个b,就是ab,数字只能是自然数
ab 表示a后面跟1到3个b,就是ab/abb/abbb三个
ab 表示a后面跟1个及以上的b,例如ab/abb/abbbbb
^.$ 表示3个字符的字符串,例如111/a1a/bbb
a|b 表示a或者b,例如a|b|2表示a/b/2三个中的一个
a|bc 表示a或者bc
(a|b)cd 表示acd/bcd两个中的一个
[ab]cd 表示acd/bcd两个中的一个
[^ab]cd 一定不能是acd/bcd中任一个
[a-z]ab 表示开头是a到z的字符,例如aab/zab/rab
[A-Z]ab 表示开头是A到Z的字符,例如Aab/Rab
[0-9]ab 表示开头是0到9的字符,例如0ab/7ab
# 第三部分
a\b \b是边界的意思,表示a字母为结尾的字符串
\ba 表示a字母为开头的字符串
a\B \B是不能为边界的意思,表示a字母不能为结尾的字符串
\Ba 表示a字母不能为开头的字符串
\d 表示[0-9]
\D 表示[^0-9]
\w 表示字母数字下划线,[A-Za-z0-9_],里面包含下划线
\W 表示[^A-Za-z0-9_],里面包含下划线
# 第四部分
\cx c表示ctrl的意思,x对应特定控制符,且必须为大小写字母
\f 换页符,对应\cL,a\fb表示ab之间有一个换页符,就是文档上下页之间的那个空字符
\n 换行符,对应\cJ,a\nb 表示ab之间有一个换行符,就是一行字符到头自动换到下一行间的空字符
\r 回车符,对应\cM,a\r\b表示ab之间有一个回车符,就是一行未到头,按enter换行的那个空字符
\t 水平制表符,对应\cI,a\tb表示ab之间有一个水平制表符,例如编程时的一个tab键表示4个空格,实现了一次水平制表符的移动
\v 垂直制表符,对应\cK,a\vb表示ab之间有一个垂直制表符,例如按向下/向上/向左/向右的任意一个箭头,都可以实现换一行从头输入
\s 匹配任何空白字符,等同于[\f\n\r\t\v]
\S 匹配任何非空白字符,与 \s正好相反
# 添加转义符表示原来的意思
\. 点号
\| 管道符号
\? 问号
\( 左括号
\) 右括号
\[ 左中括号
\] 右中括号
\{ 左大括号
\} 右大括号
\\ 右斜杠
\+ 加号
\* 星号
\t 制表符号
\^ 指数幂符号
手册表达式全集
字符 | 描述 |
---|---|
\ | 将下一个字符标记为一个特殊字符、或一个原义字符、或一个向后引用、或一个八进制转义符。例如,“n”匹配字符“n”。“\n”匹配一个换行符。串行“\\”匹配“\”而“\(”则匹配“(”。 |
^ | 匹配输入字符串的开始位置。如果设置了RegExp对象的Multiline属性,^也匹配“\n”或“\r”之后的位置。 |
$ | 匹配输入字符串的结束位置。如果设置了RegExp对象的Multiline属性,$也匹配“\n”或“\r”之前的位置。 |
* | 匹配前面的子表达式零次或多次。例如,zo能匹配“z”以及“zoo”。等价于{0,}。 |
+ | 匹配前面的子表达式一次或多次。例如,“zo+”能匹配“zo”以及“zoo”,但不能匹配“z”。+等价于{1,}。 |
? | 匹配前面的子表达式零次或一次。例如,“do(es)?”可以匹配“does”或“does”中的“do”。?等价于{0,1}。 |
{n} | n是一个非负整数。匹配确定的n次。例如,“o{2}”不能匹配“Bob”中的“o”,但是能匹配“food”中的两个o。 |
{n,} | n是一个非负整数。至少匹配n次。例如,“o{2,}”不能匹配“Bob”中的“o”,但能匹配“foooood”中的所有o。“o{1,}”等价于“o+”。“o{0,}”则等价于“o*”。 |
{n,m} | m和n均为非负整数,其中n<=m。最少匹配n次且最多匹配m次。例如,“o{1,3}”将匹配“fooooood”中的前三个o。“o{0,1}”等价于“o?”。请注意在逗号和两个数之间不能有空格。 |
? | 当该字符紧跟在任何一个其他限制符(*,+,?,{n},{n,},{n,m})后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。例如,对于字符串“oooo”,“o+?”将匹配单个“o”,而“o+”将匹配所有“o”。 |
. | 匹配除“\n”之外的任何单个字符。要匹配包括“\n”在内的任何字符,请使用像“(.|\n)”的模式。 |
(pattern) | 匹配pattern并获取这一匹配。所获取的匹配可以从产生的Matches集合得到,在VBScript中使用SubMatches集合,在JScript中则使用$0…$9属性。要匹配圆括号字符,请使用“\(”或“\)”。 |
(?:pattern) | 匹配pattern但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。这在使用或字符“(|)”来组合一个模式的各个部分是很有用。例如“industr(?:y|ies)”就是一个比“industry|industries”更简略的表达式。 |
(?=pattern) | 正向肯定预查,在任何匹配pattern的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如,“Windows(?=95|98|NT|2000)”能匹配“Windows2000”中的“Windows”,但不能匹配“Windows3.1”中的“Windows”。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始。 |
(?!pattern) | 正向否定预查,在任何不匹配pattern的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如“Windows(?!95|98|NT|2000)”能匹配“Windows3.1”中的“Windows”,但不能匹配“Windows2000”中的“Windows”。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始 |
(?<=pattern) | 反向肯定预查,与正向肯定预查类拟,只是方向相反。例如,“(?<=95|98|NT|2000)Windows”能匹配“2000Windows”中的“Windows”,但不能匹配“3.1Windows”中的“Windows”。 |
(?<!pattern) | 反向否定预查,与正向否定预查类拟,只是方向相反。例如“(?<!95|98|NT|2000)Windows”能匹配“3.1Windows”中的“Windows”,但不能匹配“2000Windows”中的“Windows”。 |
x|y | 匹配x或y。例如,“z|food”能匹配“z”或“food”。“(z|f)ood”则匹配“zood”或“food”。 |
[xyz] | 字符集合。匹配所包含的任意一个字符。例如,“[abc]”可以匹配“plain”中的“a”。 |
[^xyz] | 负值字符集合。匹配未包含的任意字符。例如,“[^abc]”可以匹配“plain”中的“p”。 |
[a-z] | 字符范围。匹配指定范围内的任意字符。例如,“[a-z]”可以匹配“a”到“z”范围内的任意小写字母字符。 |
[^a-z] | 负值字符范围。匹配任何不在指定范围内的任意字符。例如,“[^a-z]”可以匹配任何不在“a”到“z”范围内的任意字符。 |
\b | 匹配一个单词边界,也就是指单词和空格间的位置。例如,“er\b”可以匹配“never”中的“er”,但不能匹配“verb”中的“er”。 |
\B | 匹配非单词边界。“er\B”能匹配“verb”中的“er”,但不能匹配“never”中的“er”。 |
\cx | 匹配由x指明的控制字符。例如,\cM匹配一个Control-M或回车符。x的值必须为A-Z或a-z之一。否则,将c视为一个原义的“c”字符。 |
\d | 匹配一个数字字符。等价于[0-9]。 |
\D | 匹配一个非数字字符。等价于[^0-9]。 |
\f | 匹配一个换页符。等价于\x0c和\cL。 |
\n | 匹配一个换行符。等价于\x0a和\cJ。 |
\r | 匹配一个回车符。等价于\x0d和\cM。 |
\s | 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。 |
\S | 匹配任何非空白字符。等价于[^ \f\n\r\t\v]。 |
\t | 匹配一个制表符。等价于\x09和\cI。 |
\v | 匹配一个垂直制表符。等价于\x0b和\cK。 |
\w | 匹配包括下划线的任何单词字符。等价于“[A-Za-z0-9_]”。 |
\W | 匹配任何非单词字符。等价于“[^A-Za-z0-9_]”。 |
\xn | 匹配n,其中n为十六进制转义值。十六进制转义值必须为确定的两个数字长。例如,“\x41”匹配“A”。“\x041”则等价于“\x04&1”。正则表达式中可以使用ASCII编码。. |
\num | 匹配num,其中num是一个正整数。对所获取的匹配的引用。例如,“(.)\1”匹配两个连续的相同字符。 |
\n | 标识一个八进制转义值或一个向后引用。如果\n之前至少n个获取的子表达式,则n为向后引用。否则,如果n为八进制数字(0-7),则n为一个八进制转义值。 |
\nm | 标识一个八进制转义值或一个向后引用。如果\nm之前至少有nm个获得子表达式,则nm为向后引用。如果\nm之前至少有n个获取,则n为一个后跟文字m的向后引用。如果前面的条件都不满足,若n和m均为八进制数字(0-7),则\nm将匹配八进制转义值nm。 |
\nml | 如果n为八进制数字(0-3),且m和l均为八进制数字(0-7),则匹配八进制转义值_nm_l。 |
\un | 匹配n,其中n是一个用四个十六进制数字表示的Unicode字符。例如,\u00A9匹配版权符号(©)。 |
常用正则表达式
用户名 | /^[a-z0-9_-]{3,16}$/ |
---|---|
密码 | /^[a-z0-9_-]{6,18}$/ |
十六进制值 | /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ |
电子邮箱 | /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ /^[a-z\d]+(\.[a-z\d]+)*@(\da-z?)+(\.{1,2}[a-z]+)+$/ |
URL | /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-])\/?$/ |
IP 地址 | /((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ |
HTML 标签 | /^<([a-z]+)([^<]+)(?:>(.)<\/\1>|\s+\/>)$/ |
删除代码\\注释 | (?<!http:|\S)//.*$ |
Unicode编码中的汉字范围 | /^[\u2E80-\u9FFF]+$/ |
curl命令
管道符和-exec、{}和xrags
find /tmp -name "*.txt" -exec grep "password" {} \;
#find命令找tmp目录下后缀是txt的 -exec后面接继续执行的指令 {]表示find找到的内容结果 \;表示命令结束
#结果会显示找到的那个文件并打印出所在行结果
find /tmp -name "*.txt" | xargs grep "password"
#xargs表示find命令找到的内容结果
#结果比上面多显示找到文件的路径
grep命令
grep -w
Administrator@WIN-32JHG9IF81E MINGW64 /
$ curl "https://api.github.com/users/Abel13/repos?per_page=100" | grep -w clone_url
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 406k 0 406k 0 0 213k 0 --:--:-- 0:00:01 --:--:-- 213k
"clone_url": "https://github.com/Abel13/abel13.git",
"clone_url": "https://github.com/Abel13/abel13.github.io.git",
"clone_url": "https://github.com/Abel13/AcrylicWindow.git",
"clone_url": "https://github.com/Abel13/agriness_backend.git",
"clone_url": "https://github.com/Abel13/AnimatedColorfulMenu.git",
"clone_url": "https://github.com/Abel13/AnimatedMenu1.git",
"clone_url": "https://github.com/Abel13/arquitetura-de-software.git",
"clone_url": "https://github.com/Abel13/av_web_2.git",
"clone_url": "https://github.com/Abel13/BarChart.git",
"clone_url": "https://github.com/Abel13/bootstrap-material-design.git",
"clone_url": "https://github.com/Abel13/Brorsckap-template.git",
"clone_url": "https://github.com/Abel13/brunoricardosecco.git",
"clone_url": "https://github.com/Abel13/Calculator.git",
"clone_url": "https://github.com/Abel13/Chat.git",
"clone_url": "https://github.com/Abel13/Clock.git",
"clone_url": "https://github.com/Abel13/ContentLoader.git",
"clone_url": "https://github.com/Abel13/CustomControlsHandyOrg.git",
"clone_url": "https://github.com/Abel13/CustomMenu.git",
"clone_url": "https://github.com/Abel13/CustomScrollbar.git",
"clone_url": "https://github.com/Abel13/Dashboard1.git",
"clone_url": "https://github.com/Abel13/DataChangeValidation.git",
"clone_url": "https://github.com/Abel13/dctb-utfpr.git",
"clone_url": "https://github.com/Abel13/DialogHost.git",
"clone_url": "https://github.com/Abel13/diego3g.git",
"clone_url": "https://github.com/Abel13/dotnetcore_login.git",
"clone_url": "https://github.com/Abel13/DropdownMenu.git",
"clone_url": "https://github.com/Abel13/frontend.git",
"clone_url": "https://github.com/Abel13/GameProject.git",
"clone_url": "https://github.com/Abel13/gauge.git",
"clone_url": "https://github.com/Abel13/gitignore.git",
"clone_url": "https://github.com/Abel13/go_barber.git",
"clone_url": "https://github.com/Abel13/HamburgerMenu.git",
"clone_url": "https://github.com/Abel13/HorizontalList.git",
"clone_url": "https://github.com/Abel13/IF67H.git",
"clone_url": "https://github.com/Abel13/IF67I.git",
"clone_url": "https://github.com/Abel13/Instagram.git",
"clone_url": "https://github.com/Abel13/Invoice.git",
"clone_url": "https://github.com/Abel13/lereia-web.git",
"clone_url": "https://github.com/Abel13/Login1.git",
"clone_url": "https://github.com/Abel13/Login2.git",
"clone_url": "https://github.com/Abel13/LoLGoal.git",
"clone_url": "https://github.com/Abel13/Map.git",
"clone_url": "https://github.com/Abel13/MaterialDesignCustomColor.git",
"clone_url": "https://github.com/Abel13/MaterialDesignExtensions.git",
"clone_url": "https://github.com/Abel13/meek.git",
"clone_url": "https://github.com/Abel13/meek_app.git",
"clone_url": "https://github.com/Abel13/MenuMVVM.git",
"clone_url": "https://github.com/Abel13/MyMaestry.git",
"clone_url": "https://github.com/Abel13/my_commerce.git",
"clone_url": "https://github.com/Abel13/NavigationDrawer.git",
"clone_url": "https://github.com/Abel13/oneTwoThreeTesting.git",
"clone_url": "https://github.com/Abel13/PaymentScreen.git",
"clone_url": "https://github.com/Abel13/Pizzaria1.git",
"clone_url": "https://github.com/Abel13/Player1.git",
"clone_url": "https://github.com/Abel13/PointOfSale.git",
"clone_url": "https://github.com/Abel13/projg.git",
"clone_url": "https://github.com/Abel13/react-native-fcm.git",
"clone_url": "https://github.com/Abel13/Register.git",
"clone_url": "https://github.com/Abel13/RepEasy.git",
"clone_url": "https://github.com/Abel13/responsivelayout.git",
"clone_url": "https://github.com/Abel13/sa-soilcorrection.git",
"clone_url": "https://github.com/Abel13/SheepFinance.git",
"clone_url": "https://github.com/Abel13/SheepStock.git",
"clone_url": "https://github.com/Abel13/ShoppingCart.git",
"clone_url": "https://github.com/Abel13/SoftwareEngineeringEPFComposer.git",
"clone_url": "https://github.com/Abel13/TabMenu.git",
"clone_url": "https://github.com/Abel13/TabMenu2.git",
"clone_url": "https://github.com/Abel13/tcc.git",
"clone_url": "https://github.com/Abel13/tetris.git",
"clone_url": "https://github.com/Abel13/Transitions.git",
"clone_url": "https://github.com/Abel13/tutoriais.git",
"clone_url": "https://github.com/Abel13/twitter.github.io.git",
"clone_url": "https://github.com/Abel13/vscode-config.git",
"clone_url": "https://github.com/Abel13/web1project.git",
"clone_url": "https://github.com/Abel13/web_if67i.git",
"clone_url": "https://github.com/Abel13/workshopUFF.git",
grep -o
Administrator@WIN-32JHG9IF81E MINGW64 /
$ curl "https://api.github.com/users/Abel13/repos?per_page=100" | grep -w clone_url| grep -o 'https://.*git'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 406k 100 406k 0 0 552k 0 --:--:-- --:--:-- --:--:-- 552k
https://github.com/Abel13/abel13.git
https://github.com/Abel13/abel13.github.io.git
https://github.com/Abel13/AcrylicWindow.git
https://github.com/Abel13/agriness_backend.git
https://github.com/Abel13/AnimatedColorfulMenu.git
https://github.com/Abel13/AnimatedMenu1.git
https://github.com/Abel13/arquitetura-de-software.git
https://github.com/Abel13/av_web_2.git
https://github.com/Abel13/BarChart.git
https://github.com/Abel13/bootstrap-material-design.git
https://github.com/Abel13/Brorsckap-template.git
https://github.com/Abel13/brunoricardosecco.git
https://github.com/Abel13/Calculator.git
https://github.com/Abel13/Chat.git
https://github.com/Abel13/Clock.git
https://github.com/Abel13/ContentLoader.git
https://github.com/Abel13/CustomControlsHandyOrg.git
https://github.com/Abel13/CustomMenu.git
https://github.com/Abel13/CustomScrollbar.git
https://github.com/Abel13/Dashboard1.git
https://github.com/Abel13/DataChangeValidation.git
https://github.com/Abel13/dctb-utfpr.git
https://github.com/Abel13/DialogHost.git
https://github.com/Abel13/diego3g.git
https://github.com/Abel13/dotnetcore_login.git
https://github.com/Abel13/DropdownMenu.git
https://github.com/Abel13/frontend.git
https://github.com/Abel13/GameProject.git
https://github.com/Abel13/gauge.git
https://github.com/Abel13/gitignore.git
https://github.com/Abel13/go_barber.git
https://github.com/Abel13/HamburgerMenu.git
https://github.com/Abel13/HorizontalList.git
https://github.com/Abel13/IF67H.git
https://github.com/Abel13/IF67I.git
https://github.com/Abel13/Instagram.git
https://github.com/Abel13/Invoice.git
https://github.com/Abel13/lereia-web.git
https://github.com/Abel13/Login1.git
https://github.com/Abel13/Login2.git
https://github.com/Abel13/LoLGoal.git
https://github.com/Abel13/Map.git
https://github.com/Abel13/MaterialDesignCustomColor.git
https://github.com/Abel13/MaterialDesignExtensions.git
https://github.com/Abel13/meek.git
https://github.com/Abel13/meek_app.git
https://github.com/Abel13/MenuMVVM.git
https://github.com/Abel13/MyMaestry.git
https://github.com/Abel13/my_commerce.git
https://github.com/Abel13/NavigationDrawer.git
https://github.com/Abel13/oneTwoThreeTesting.git
https://github.com/Abel13/PaymentScreen.git
https://github.com/Abel13/Pizzaria1.git
https://github.com/Abel13/Player1.git
https://github.com/Abel13/PointOfSale.git
https://github.com/Abel13/projg.git
https://github.com/Abel13/react-native-fcm.git
https://github.com/Abel13/Register.git
https://github.com/Abel13/RepEasy.git
https://github.com/Abel13/responsivelayout.git
https://github.com/Abel13/sa-soilcorrection.git
https://github.com/Abel13/SheepFinance.git
https://github.com/Abel13/SheepStock.git
https://github.com/Abel13/ShoppingCart.git
https://github.com/Abel13/SoftwareEngineeringEPFComposer.git
https://github.com/Abel13/TabMenu.git
https://github.com/Abel13/TabMenu2.git
https://github.com/Abel13/tcc.git
https://github.com/Abel13/tetris.git
https://github.com/Abel13/Transitions.git
https://github.com/Abel13/tutoriais.git
https://github.com/Abel13/twitter.github.io.git
https://github.com/Abel13/vscode-config.git
https://github.com/Abel13/web1project.git
https://github.com/Abel13/web_if67i.git
https://github.com/Abel13/workshopUFF.git
获取gogs的所有开放仓库
参考:https://www.cnblogs.com/Lzl678/p/12189120.html
Administrator@WIN-32JHG9IF81E MINGW64 /
$ curl "http://git.jishutao.com/explore/repos" |grep -w 'name" href'|grep -o '/.*>FrontEnd'|grep -o '.*"'|grep -o '.*\w'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14730 0 14730 0 0 77808 0 --:--:-- --:--:-- --:--:-- 78770
/FrontEnd/official-web-manage
/FrontEnd/kede-client
/FrontEnd/kede-tool-weapp
/FrontEnd/kede-currency-officialWeb
/FrontEnd/kede-officialWeb-currency-client
/FrontEnd/kede-simple-client
/FrontEnd/jitao-web
/FrontEnd/jitao-H5
/FrontEnd/afanti-client
/FrontEnd/jitao-client
/FrontEnd/antd-kede-client
/FrontEnd/afanti-web
/FrontEnd/kede-HN-officialWeb-client
/FrontEnd/kede-weapp
sort命令
中文排序参考:https://zhuanlan.zhihu.com/p/148195156
解决方案:
LC_ALL=C sort a.txt | LC_ALL=C uniq
或者
export LC_ALL=C sort a.txt | uniq
例子:
sort -t ',' -k40,40 -S 4G -T tmp/ a.csv >ok.csv
#表示以空格为划分列数,根据第40列使用4G内存对a.csv进行排序
具体实例:
可以参考:http://linux.51yip.com/search/sort
该网站很多实例、手册
sort⽤法
⼀、sort⽤法
sort将⽂件的每⼀⾏作为⼀个单位,相互⽐较,⽐较原则是从⾸字符向后,依次按ASCII码值进⾏⽐较,最后将他们按升序输出。
vim 1.txt
1:datadir=/aaa/zzz:
2:basedir=:cc
4:datadir=/sdfsfsd:dd
3:basedir=/data:gg
(1)、-r 对分类进⾏次序或者⽐较求逆
(2)、-u 删除所有复制⾏
(3)、-n 指定分类是域上的数据分类,-n依照数值的⼤⼩排序
默认是按照ASCII值进⾏排序,
你有没有遇到过10⽐2⼩的情况。我反正遇到过。出现这种情况是由于排序程序将这些数字按字符来排序了,排序程序会先⽐较1和2,显然
1⼩,所以就将10放在2前⾯喽。这也是sort的⼀贯作风。
# cat 2.txt | sort
1
10
11
19
2
5
# cat 2.txt | sort -n
1
2
5
10
11
19
(4)、 sort的-t选项(制定分割符)和-k选项指定列数
# cat facebook.txt
banana:30:5.5
apple:10:2.5
pear:90:2.3
orange:20:3.4
这个⽂件有三列,列与列之间⽤冒号隔开了,第⼀列表⽰⽔果类型,第⼆列表⽰⽔果数量,第三列表⽰⽔果价格。那么我想以⽔果数量来排
序,也就是以第⼆列来排序,如何利⽤sort实现?幸好,sort提供了-t选项,后⾯可以设定间隔符。指定了间隔符之后,就可以⽤-k来指定列
数了。
# sort -n -k 2 -t ‘:’ facebook.txt #使⽤-k制定第2列进⾏排序,
apple:10:2.5
orange:20:3.4
banana:30:5.5
pear:90:2.3
(5) 4sort的-o选项
由于sort默认是把结果输出到标准输出,所以需要⽤重定向才能将结果写⼊⽂件,形如sort filename > newfile。
但是,如果你想把排序结果输出到原⽂件中,⽤重定向可就不⾏了。
sort -r number.txt -o number.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
其他的sort常⽤选项
-f会将⼩写字母都转换为⼤写字母来进⾏⽐较,亦即忽略⼤⼩写
-c会检查⽂件是否已排好序,如果乱序,则输出第⼀个乱序的⾏的相关信息,最后返回1
-C会检查⽂件是否已排好序,如果乱序,不输出内容,仅返回1
-M会以⽉份来排序,⽐如JAN⼩于FEB等等
-b会忽略每⼀⾏前⾯的所有空⽩部分,从第⼀个可见字符开始⽐较。
有时候学习脚本,你会发现sort命令后⾯跟了⼀堆类似-k1,2,或者-k1.2 -k3.4的东东,有些匪夷所思。今天,我们就来搞定它—-k选项!
1 准备素材
$ cat facebook.txt
google 110 5000
baidu 100 5000
guge 50 3000
sohu 100 4500
第⼀个域是公司名称,第⼆个域是公司⼈数,第三个域是员⼯平均⼯资。(除了公司名称,其他的别信,都瞎写的^_^)
2 我想让这个⽂件按公司的字母顺序排序,也就是按第⼀个域进⾏排序:(这个facebook.txt⽂件有三个域)
$ sort -t ‘ ‘ -k 1 facebook.txt
baidu 100 5000
google 110 5000
guge 50 3000
sohu 100 4500
看到了吧,就直接⽤-k 1设定就可以了。(其实此处并不严格,稍后你就会知道)
3 我想让facebook.txt按照公司⼈数排序
$ sort -n -t ‘ ‘ -k 2 facebook.txt
guge 50 3000
baidu 100 5000
sohu 100 4500
google 110 5000
不⽤解释,我相信你能懂。
但是,此处出现了问题,那就是baidu和sohu的公司⼈数相同,都是100⼈,这个时候怎么办呢?按照默认规矩,是从第⼀个域开始进⾏升
序排序,因此baidu排在了sohu前⾯。
4 我想让facebook.txt按照公司⼈数排序,⼈数相同的按照员⼯平均⼯资升序排序:
$ sort -n -t ‘ ‘ -k 2 -k 3 facebook.txt
guge 50 3000
sohu 100 4500
baidu 100 5000
google 110 5000
看,我们加了⼀个-k2 -k3就解决了问题。对滴,sort⽀持这种设定,就是说设定域排序的优先级,先以第2个域进⾏排序,如果相同,再以第
3个域进⾏排序。(如果你愿意,可以⼀直这么写下去,设定很多个排序优先级)
5 我想让facebook.txt按照员⼯⼯资降序排序,如果员⼯⼈数相同的,则按照公司⼈数升序排序:(这个有点难度喽)
$ sort -n -t ‘ ‘ -k 3r -k 2 facebook.txt
baidu 100 5000
google 110 5000
sohu 100 4500
guge 50 3000
此处有使⽤了⼀些⼩技巧,你仔细看看,在-k 3后⾯偷偷加上了⼀个⼩写字母r。你想想,再结合我们,能得到答案么?揭晓:r和-r选项的作
⽤是⼀样的,就是表⽰逆序。因为sort默认是按照升序排序的,所以此处需要加上r表⽰第三个域(员⼯平均⼯资)是按照降序排序。此处你
还可以加上n,就表⽰对这个域进⾏排序时,要按照数值⼤⼩进⾏排序,举个例⼦吧:
$ sort -t ‘ ‘ -k 3nr -k 2n facebook.txt
baidu 100 5000
google 110 5000
sohu 100 4500
guge 50 3000
看,我们去掉了最前⾯的-n选项,⽽是将它加⼊到了每⼀个-k选项中了。
6 -k选项的具体语法格式
要继续往下深⼊的话,就不得不来点理论知识。你需要了解-k选项的语法格式,如下:
[ FStart [ .CStart ] ] [ Modifier ] [ , [ FEnd [ .CEnd ] ][ Modifier ] ]
这个语法格式可以被其中的逗号(“,”)分为两⼤部分,Start部分和End部分。
先给你灌输⼀个思想,那就是“如果不设定End部分,那么就认为End被设定为⾏尾”。这个概念很重要的,但往往你不会重视它。
Start部分也由三部分组成,其中的Modifier部分就是我们之前说过的类似n和r的选项部分。我们重点说说Start部分的FStart和C.Start。
C.Start也是可以省略的,省略的话就表⽰从本域的开头部分开始。之前例⼦中的-k 2和-k 3就是省略了C.Start的例⼦喽。
FStart.CStart,其中FStart就是表⽰使⽤的域,⽽CStart则表⽰在FStart域中从第⼏个字符开始算“排序⾸字符”。
同理,在End部分中,你可以设定FEnd.CEnd,如果你省略.CEnd,则表⽰结尾到“域尾”,即本域的最后⼀个字符。或者,如果你将CEnd设
定为0(零),也是表⽰结尾到“域尾”。
7 突发奇想,从公司英⽂名称的第⼆个字母开始进⾏排序:
$ sort -t ‘ ‘ -k 1.2 facebook.txt
baidu 100 5000
sohu 100 4500
google 110 5000
guge 50 3000
看,我们使⽤了-k 1.2,这就表⽰对第⼀个域的第⼆个字符开始到本域的最后⼀个字符为⽌的字符串进⾏排序。你会发现baidu因为第⼆个字
母是a⽽名列榜⾸。sohu和 google第⼆个字符都是o,但sohu的h在google的o前⾯,所以两者分别排在第⼆和第三。guge只能屈居第四了。
8 ⼜突发奇想,,只针对公司英⽂名称的第⼆个字母进⾏排序,如果相同的按照员⼯⼯资进⾏降序排序:
$ sort -t ‘ ‘ -k 1.2,1.2 -k 3,3nr facebook.txt
baidu 100 5000
google 110 5000
sohu 100 4500
guge 50 3000
由于只对第⼆个字母进⾏排序,所以我们使⽤了-k 1.2,1.2的表⽰⽅式,表⽰我们“只”对第⼆个字母进⾏排序。(如果你问“我使⽤-k 1.2怎么
不⾏?”,当然不⾏,因为你省略了End部分,这就意味着你将对从第⼆个字母起到本域最后⼀个字符为⽌的字符串进⾏排序)。对于员⼯⼯
资进⾏排序,我们也使⽤了-k 3,3,这是最准确的表述,表⽰我们“只”对本域进⾏排序,因为如果你省略了后⾯的3,就变成了我们“对第3个
域开始到最后⼀个域位置的内容进⾏排序” 了。
9 在modifier部分还可以⽤到哪些选项?
可以⽤到b、d、f、i、n 或 r。
其中n和r你肯定已经很熟悉了。
b表⽰忽略本域的签到空⽩符号。
d表⽰对本域按照字典顺序排序(即,只考虑空⽩和字母)。
f表⽰对本域忽略⼤⼩写进⾏排序。
i表⽰忽略“不可打印字符”,只针对可打印字符进⾏排序。(有些ASCII就是不可打印字符,⽐如\a是报警,\b是退格,\n是换⾏,\r是回车等
等)
10 思考思考关于-k和-u联合使⽤的例⼦:
$ cat facebook.txt
google 110 5000
baidu 100 5000
guge 50 3000
sohu 100 4500
这是最原始的facebook.txt⽂件。
$ sort -n -k 2 facebook.txt
guge 50 3000
baidu 100 5000
sohu 100 4500
google 110 5000
$ sort -n -k 2 -u facebook.txt
guge 50 3000
baidu 100 5000
google 110 5000
当设定以公司员⼯域进⾏数值排序,然后加-u后,sohu⼀⾏就被删除了!原来-u只识别⽤-k设定的域,发现相同,就将后续相同的⾏都删
除。
$ sort -k 1 -u facebook.txt
baidu 100 5000
google 110 5000
guge 50 3000
sohu 100 4500
$ sort -k 1.1,1.1 -u facebook.txt
baidu 100 5000
google 110 5000
sohu 100 4500
这个例⼦也同理,开头字符是g的guge就没有幸免于难。
$ sort -n -k 2 -k 3 -u facebook.txt
guge 50 3000
sohu 100 4500
baidu 100 5000
google 110 5000
咦!这⾥设置了两层排序优先级的情况下,使⽤-u就没有删除任何⾏。原来-u是会权衡所有-k选项,将都相同的才会删除,只要其中有⼀级
不同都不会轻易删除的:)(不信,你可以⾃⼰加⼀⾏sina 100 4500试试看)
11 最诡异的排序:
$ sort -n -k 2.2,3.1 facebook.txt
guge 50 3000
baidu 100 5000
sohu 100 4500
google 110 5000
以第⼆个域的第⼆个字符开始到第三个域的第⼀个字符结束的部分进⾏排序。
第⼀⾏,会提取0 3,第⼆⾏提取00 5,第三⾏提取00 4,第四⾏提取10 5。
⼜因为sort认为0⼩于00⼩于000⼩于0000….
因此0 3肯定是在第⼀个。10 5肯定是在最后⼀个。但为什么00 5却在00 4前⾯呢?(你可以⾃⼰做实验思考⼀下。)
答案揭晓:原来“跨域的设定是个假象”,sort只会⽐较第⼆个域的第⼆个字符到第⼆个域的最后⼀个字符的部分,⽽不会把第三个域的开头字
符纳⼊⽐较范围。当发现00和00相同时,sort就会⾃动⽐较第⼀个域去了。当然baidu在sohu前⾯了。⽤⼀个范例即可证实:
$ sort -n -k 2.2,3.1 -k 1,1r facebook.txt
guge 50 3000
sohu 100 4500
baidu 100 5000
google 110 5000
12 有时候在sort命令后会看到+1 -2这些符号,这是什么东东?
关于这种语法,最新的sort是这么进⾏解释的:
On older systems, `sort’ supports an obsolete origin-zero syntax `+POS1 [-POS2]‘ for specifying sort keys. POSIX 1003.1-2001 (*note
Standards conformance::) does not allow this; use `-k’ instead.
原来,这种古⽼的表⽰⽅式已经被淘汰了,以后可以理直⽓壮的鄙视使⽤这种表⽰⽅法的脚本喽!
(为了防⽌古⽼脚本的存在,在这再说⼀下这种表⽰⽅法,加号表⽰Start部分,减号表⽰End部分。最最重要的⼀点是,这种⽅式⽅法是从
0开始计数的,以前所说的第⼀个域,在此被表⽰为第0个域。以前的第2个字符,在此表⽰为第1个字符。明⽩?)
wget命令
参考:https://chowdera.com/2022/01/202201220532092486.html
wget -r -np -nH -R index.html http://url/including/files/you/want/to/download/
各个参数的含义:
-r : 遍历所有子目录
-np : 不到上一层子目录去
-nH : 不要将文件保存到主机名文件夹
-R index.html : 不下载 index.html 文件