当前位置:网站首页>Make mistakes small yards artisan study room 】 【 the ladder of the progress of children
Make mistakes small yards artisan study room 】 【 the ladder of the progress of children
2022-08-08 14:03:00 【small coders】
碎碎念
- Coming up with this article today,You can only fall one somersault in the same place,Repeated mistakes will definitely be knocked on the head by the old code farmers
- Combing this article originates from3月份参加NOI OnlineThere is no full text comparison of output file contents for the test matches,Just comparing a few values,lead to zero explosion( ̄﹏ ̄;)
- The title is from the old code farmer,Too much chicken soup for the soul,I want to call him later”Tang Chicken Soup“了.(*^_^*)
准备测试文件
- mode_ex1.ans
4
1
5
1
4
2
4
8
2
1
2
3
4
5
- mode_ex1-2.ans
- 修改了第13行数据:4 -> 6
4
1
5
1
4
2
4
8
2
1
2
3
6
5
- mode_ex1-3.ans
- Same as the first file
4
1
5
1
4
2
4
8
2
1
2
3
4
5
- mode_ex1-4.ans
- 第二行:1 -> 4
- 倒数第二行:4 -> 6
- The second and penultimate rows of data have been modified
4
2
5
1
4
2
4
8
2
1
2
3
6
5
Windows
文件内容比较命令:fc
- 查看fc帮助
D:\day1\mode>fc /?
比较两个文件或两个文件集并显示它们之间
的不同
FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
[drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2
/A 只显示每个不同处的第一行和最后一行.
/B 执行二进制比较.
/C 不分大小写.
/L 将文件作为 ASCII 文字比较.
/LBn Sets the maximum value of consecutive mismatches as specified
的行数.
/N 在 ASCII 比较上显示行数.
/OFF[LINE] 不要跳过带有脱机属性集的文件.
/T 不要将制表符扩充到空格.
/U 将文件作为 UNICODE 文本文件比较.
/W 为了比较而压缩空白(制表符和空格).
/nnnn Must be continuous after specifying mismatch
匹配的行数.
[drive1:][path1]filename1
指定要比较的第一个文件或第一个文件集.
[drive2:][path2]filename2
指定要比较的第二个文件或第二个文件集.
示例
比较:mode_ex1.ans 和 mode_ex1-3.ans
- 内容一样
D:\day1\mode>fc mode_ex1.ans mode_ex1-3.ans
正在比较文件 mode_ex1.ans 和 MODE_EX1-3.ANS
FC: 找不到差异
比较:mode_ex1.ans 和 mode_ex1-2.ans
- Modified penultimate2行数据:4 -> 6
D:\day1\mode>fc mode_ex1.ans mode_ex1-2.ans
正在比较文件 mode_ex1.ans 和 MODE_EX1-2.ANS
***** mode_ex1.ans
3
4
5
***** MODE_EX1-2.ANS
3
6
5
*****
比较:mode_ex1.ans 和 mode_ex1-4.ans
- The two lines are not the same,Positive second row and penultimate row
D:\day1\mode>fc mode_ex1.ans mode_ex1-4.ans
正在比较文件 mode_ex1.ans 和 MODE_EX1-4.ANS
***** mode_ex1.ans
4
1
5
***** MODE_EX1-4.ANS
4
2
5
*****
***** mode_ex1.ans
3
4
5
***** MODE_EX1-4.ANS
3
6
5
*****
Linux
文件内容比较命令:diff
- 查看diff帮助
[email protected]:~$ diff --help
Usage: diff [OPTION]... FILES
Compare FILES line by line.
Mandatory arguments to long options are mandatory for short options too.
--normal output a normal diff (the default)
-q, --brief report only when files differ
-s, --report-identical-files report when two files are the same
-c, -C NUM, --context[=NUM] output NUM (default 3) lines of copied context
-u, -U NUM, --unified[=NUM] output NUM (default 3) lines of unified context
-e, --ed output an ed script
-n, --rcs output an RCS format diff
-y, --side-by-side output in two columns
-W, --width=NUM output at most NUM (default 130) print columns
--left-column output only the left column of common lines
--suppress-common-lines do not output common lines
-p, --show-c-function show which C function each change is in
-F, --show-function-line=RE show the most recent line matching RE
--label LABEL use LABEL instead of file name and timestamp
(can be repeated)
-t, --expand-tabs expand tabs to spaces in output
-T, --initial-tab make tabs line up by prepending a tab
--tabsize=NUM tab stops every NUM (default 8) print columns
--suppress-blank-empty suppress space or tab before empty output lines
-l, --paginate pass output through 'pr' to paginate it
-r, --recursive recursively compare any subdirectories found
--no-dereference don't follow symbolic links
-N, --new-file treat absent files as empty
--unidirectional-new-file treat absent first files as empty
--ignore-file-name-case ignore case when comparing file names
--no-ignore-file-name-case consider case when comparing file names
-x, --exclude=PAT exclude files that match PAT
-X, --exclude-from=FILE exclude files that match any pattern in FILE
-S, --starting-file=FILE start with FILE when comparing directories
--from-file=FILE1 compare FILE1 to all operands;
FILE1 can be a directory
--to-file=FILE2 compare all operands to FILE2;
FILE2 can be a directory
-i, --ignore-case ignore case differences in file contents
-E, --ignore-tab-expansion ignore changes due to tab expansion
-Z, --ignore-trailing-space ignore white space at line end
-b, --ignore-space-change ignore changes in the amount of white space
-w, --ignore-all-space ignore all white space
-B, --ignore-blank-lines ignore changes where lines are all blank
-I, --ignore-matching-lines=RE ignore changes where all lines match RE
-a, --text treat all files as text
--strip-trailing-cr strip trailing carriage return on input
-D, --ifdef=NAME output merged file with '#ifdef NAME' diffs
--GTYPE-group-format=GFMT format GTYPE input groups with GFMT
--line-format=LFMT format all input lines with LFMT
--LTYPE-line-format=LFMT format LTYPE input lines with LFMT
These format options provide fine-grained control over the output
of diff, generalizing -D/--ifdef.
LTYPE is 'old', 'new', or 'unchanged'. GTYPE is LTYPE or 'changed'.
GFMT (only) may contain:
%< lines from FILE1
%> lines from FILE2
%= lines common to FILE1 and FILE2
%[-][WIDTH][.[PREC]]{doxX}LETTER printf-style spec for LETTER
LETTERs are as follows for new group, lower case for old group:
F first line number
L last line number
N number of lines = L-F+1
E F-1
M L+1
%(A=B?T:E) if A equals B then T else E
LFMT (only) may contain:
%L contents of line
%l contents of line, excluding any trailing newline
%[-][WIDTH][.[PREC]]{doxX}n printf-style spec for input line number
Both GFMT and LFMT may contain:
%% %
%c'C' the single character C
%c'\OOO' the character with octal code OOO
C the character C (other characters represent themselves)
-d, --minimal try hard to find a smaller set of changes
--horizon-lines=NUM keep NUM lines of the common prefix and suffix
--speed-large-files assume large files and many scattered small changes
--color[=WHEN] colorize the output; WHEN can be 'never', 'always',
or 'auto' (the default)
--palette=PALETTE the colors to use when --color is active; PALETTE is
a colon-separated list of terminfo capabilities
--help display this help and exit
-v, --version output version information and exit
FILES are 'FILE1 FILE2' or 'DIR1 DIR2' or 'DIR FILE' or 'FILE DIR'.
If --from-file or --to-file is given, there are no restrictions on FILE(s).
If a FILE is '-', read standard input.
Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.
Report bugs to: [email protected]
GNU diffutils home page: <https://www.gnu.org/software/diffutils/>
General help using GNU software: <https://www.gnu.org/gethelp/>
示例
- Displays a list of files in a directory
[email protected]:~/Desktop/coder/mode$ ls -la
total 4872
drwxrwxrwx 2 coder coder 4096 Jun 13 00:52 .
drwxrwxr-x 3 coder coder 4096 Jun 13 01:06 ..
-rwxrw-rw- 1 coder coder 42 Jun 13 00:48 mode_ex1-2.ans
-rwxrw-rw- 1 coder coder 40 Jun 13 00:50 mode_ex1-3.ans
-rwxrw-rw- 1 coder coder 40 Jun 13 00:52 mode_ex1-4.ans
-rwxrw-rw- 1 coder coder 28 May 2 07:54 mode_ex1.ans
-rwxrw-rw- 1 coder coder 52 May 2 07:54 mode_ex1.in
-rwxrw-rw- 1 coder coder 178 May 2 07:48 mode_ex2.ans
-rwxrw-rw- 1 coder coder 4954289 May 2 07:48 mode_ex2.in
- 常规命令
- "|"表示前后2个文件内容有不同
- "<"表示后面文件比前面文件少了1行内容
- ">"表示后面文件比前面文件多了1行内容
- 比较:mode_ex1.ans 和 mode_ex1-3.ans
- 内容一样
[email protected]:~/Desktop/coder/mode$ diff mode_ex1.ans mode_ex1-3.ans
1,14c1,14
< 4
< 1
< 5
< 1
< 4
< 2
< 4
< 8
< 2
< 1
< 2
< 3
< 4
< 5
---
> 4
> 1
> 5
> 1
> 4
> 2
> 4
> 8
> 2
> 1
> 2
> 3
> 4
> 5
\ No newline at end of file
- 奇怪吧,The file contents are named the same,The displayed results have indeed changed,接下来用file查看文件编码格式
- Windows中:The carriage return is ‘\r’,回到行首;换行符为 ‘\n’,换到当前位置的下一行;
- Linux系统中:I don't think it is necessary to add two characters at the end of each line,So there is only a newline at the end,即‘\n’;
- Mac系统中:There is only a carriage return at the end of each line,即‘\r’
- The file encoding format is messed up,mode_ex1-3.ansfile is againwindows下拷贝mode_ex1.ans内容,Newly generated,Each line is preceded by a carriage return line feed,So it is different when comparing
[email protected]:~/Desktop/coder/mode$ file mode_ex1.ans
mode_ex1.ans: ASCII text
[email protected]:~/Desktop/coder/mode$ file mode_ex1-3.ans
mode_ex1-3.ans: ASCII text, with CRLF line terminators
可以用Linux下的命令:sed进行替换
- 参考命令
sed -i "s/\r//" mode_ex1-3.ans
- 替换
[email protected]:~/Desktop/coder/mode$ sed -i "s/\r//" mode_ex1-3.ans
[email protected]:~/Desktop/coder/mode$ sed -i "s/\r//" mode_ex1-2.ans
[email protected]:~/Desktop/coder/mode$ sed -i "s/\r//" mode_ex1-4.ans
[email protected]:~/Desktop/coder/mode$ file ^C
[email protected]:~/Desktop/coder/mode$ file mode_ex1-2.ans
mode_ex1-2.ans: ASCII text
[email protected]:~/Desktop/coder/mode$ file mode_ex1-3.ans
mode_ex1-3.ans: ASCII text
[email protected]:~/Desktop/coder/mode$ file mode_ex1-4.ans
mode_ex1-4.ans: ASCII text
- Continue to compare after replacement
[email protected]:~/Desktop/coder/mode$ file mode_ex1.ans mode_ex1-3.ans
mode_ex1.ans: ASCII text
mode_ex1-3.ans: ASCII text
比较:mode_ex1.ans 和 mode_ex1-3.ans
- 两个文件内容相同
[email protected]:~/Desktop/coder/mode$ diff mode_ex1.ans mode_ex1-3.ans
[email protected]:~/Desktop/coder/mode$
Because the content is exactly the same,So no difference is shown
比较:mode_ex1.ans 和 mode_ex1-2.ans
- Only one line is different,倒数第二行
[email protected]:~/Desktop/coder/mode$ diff mode_ex1.ans mode_ex1-2.ans
13c13
< 4
---
> 6
上面的"13c13"表示两个文件在第13行内容不同
比较:mode_ex1.ans 和 mode_ex1-4.ans
- The two lines are not the same,Positive second row and penultimate row
[email protected]:~/Desktop/coder/mode$ diff mode_ex1.ans mode_ex1-4.ans
2c2
< 1
---
> 2
13,14c13,14
< 4
< 5
---
> 6
> 5
\ No newline at end of file
上面的"2c2"表示两个文件在第2行内容不同 "13,14c13,14"表示两个文件在第13,14行内容不同, ==但其实只有13Line content is different,没搞明白==
边栏推荐
- sample function—R language
- win32&mfc————win32菜单栏&库
- 论文理解:“Self-adaptive loss balanced Physics-informed neural networks“
- 【小码匠自习室】让错误成为孩子进步的阶梯
- 作为一个十年卷王,告诫你们年轻人应该如何才能认清自己的价值
- R语言ggplot2可视化:使用ggpubr包的ggline函数可视化折线图(点线图、line plot)、设置add参数为mean可视化不同水平均值的折线图
- 活动报名| StreamNative 受邀参与 ITPUB 在线技术沙龙
- 京东三面惨遭被虐,关于redis,高并发,分布式,问懵了
- Flink1.15源码阅读——StreamGraph流图
- 【Rust—LeetCode题解】1408.数组中的字符串匹配
猜你喜欢
QWebAssembly中文适配
【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...
Tsinghua | GLM-130B: An Open Bilingual Pre-training Model
Implementation of FIR filter based on FPGA (1) - using fir1 function design
window停掉指定端口的进程
win32&mfc————win32菜单栏&库
LeetCode简单题之统计星号
浅谈 Redis 的底层数据结构
HackTheBox | Horizontall
【Rust—LeetCode题解】1.两数之和
随机推荐
从零开始,如何拥有自己的博客网站【华为云至简致远】
flutter 身兼数职的getx —— 简介
【Redis】位图以及位图的使用场景(统计在线人数和用户在线状态)
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化堆叠的柱状图(stacked bar plot)、palette参数自定义不同水平柱状图边框以及填充的颜色
Full of dry goods, Yu Jingxin class of the Institute of Information Technology, Chinese Academy of Sciences will help you get academic research and thesis writing skills
Kotlin系列之let、with、run、apply、also函数的使用
[Redis] Bitmap and usage scenarios of bitmap (statistics of online people and user online status)
初窥门径代码起手,Go lang1.18入门精炼教程,由白丁入鸿儒,首次运行golang程序EP01
一桩事先张扬的网红书店倒闭案
【os.path】的相关用法(持更)
idea 好工具
【系统设计】S3 对象存储
【小码匠自习室】AGC023-A :为啥总是N连发?为啥总遇到大神?
R语言ggplot2可视化:使用ggpubr包的ggdonutchart函数可视化甜甜圈图(donut chart)、为甜甜圈图添加自定义标签(包含文本内容以及数值百分比)、lab.font参数设置标
【小码匠自习室】ABC084 - D:喜欢这样的大神,超有才华
基于Nodejs的医生预约平台的设计和实现
【Rust—LeetCode题解】1408.数组中的字符串匹配
QtWebassembly遇到的一些报错问题及解决方案
年初离职,学习半年源码,终于拿到了蚂蚁Offer,分享面试过程
现在网上开户安全么?接着证券开户选择哪个证券?