范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文

文本常见处理工具介绍和学习

  1、文件内容查看命令
  1.1查看文本文件内容
  cat 可以查看文本内容
  格式:cat [OPTION]... [FILE]...
  常见选项:
  -E:显示行结束符$
  -A:显示所有控制符
  -n:对显示出的每一行进行编号
  -b:非空行编号
  tac 逆向显示文本内容
  nl 显示行号,相当于
  cat -b rev 将同一行的内容逆向显示
  -s:压缩连续的空行成一行
  1.2查看非文本文件内容
  1.2.1 hexdump
  范例:hexdump -C -n 512 /dev/sda 00000000 eb 63 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0 |.c..............|     echo {a..z} | tr -d " "|hexdump -C  00000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 |abcdefghijklmnop|  00000010 71 72 73 74 75 76 77 78 79 7a 0a |qrstuvwxyz.|  0000001b
  1.2.2 od
  od 即 dump files in octal and other formats
  范例:[root@centos8 ~]#echo {a..z} | tr -d " "|od -t x 0000000 64636261 68676665 6c6b6a69 706f6e6d 0000020 74737271 78777675 000a7a79 0000033 [root@centos8 ~]#echo {a..z} | tr -d " "|od -t x1 0000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 0000020 71 72 73 74 75 76 77 78 79 7a 0a 0000033 [root@centos8 ~]#echo {a..z} | tr -d " "|od -t x1z 0000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 >abcdefghijklmnop< 0000020 71 72 73 74 75 76 77 78 79 7a 0a                 >qrstuvwxyz.< 0000033
  1.2.3 xxdecho {a..z} | tr -d " "|xxd  0000000: 6162 6364 6566 6768 696a 6b6c 6d6e 6f70 abcdefghijklmnop 0000010: 7172 7374 7576 7778 797a 0a             qrstuvwxyz.2 、分页查看文件内容
  more 可以实现分页查看文件,可以配合管道实现输出信息的分页
  格式more [OPTIONS...] FILE...
  选项:
  -d: 显示翻页及退出提示
  less 也可以实现分页查看文件或STDIN输出
  查看时有用的命令包括:
  /文本 搜索 文本
  n/N 跳到下一个 或 上一个匹配
  less 命令是man命令使用的分页器
  范例:[root@centos8 ~]#cat /etc/init.d/functions |less  # -*-Shell-script-*- # # functions This file contains functions to be used by most or all #       shell scripts in the /etc/init.d directory. # TEXTDOMAIN=initscripts # Make sure umask is sane umask 022 # Set up a default search path. PATH="/sbin:/usr/sbin:/bin:/usr/bin" export PATH ...省略...3 、显示文本前或后行内容
  head 可以显示文件或标准输入的前面行
  格式:head [OPTION]... [FILE]...
  选项:
  -c # 指定获取前#字节
  -n # 指定获取前#行
  -# 同上
  范例:[root@centos8 ~]#head -n 3 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin   [root@centos8 ~]#head -3 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin  [root@centos8 ~]#echo a我b | head -c4 a我[root@centos8 ~]# [root@centos8 ~]#cat /dev/urandom | tr -dc "[:alnum:]"| head -c10 G755MlZatW[root@centos8 ~]#cat /dev/urandom | tr -dc "[:alnum:]"| head -c10 ASsax6DeBz[root@centos8 ~]#cat /dev/urandom | tr -dc "[:alnum:]"| head -c10 |  tee pass.txt | passwd --stdin mage Changing password for user mage. passwd: all authentication tokens updated successfully. [root@centos8 ~]#cat pass.txt  AGT952Essg[root@centos8 ~]#su - wang [wang@centos8 ~]$su - mage Password:
  tail 和head 相反,查看文件或标准输入的倒数行
  格式:tail [OPTION]... [FILE]...
  -c # 指定获取后#字节
  -n # 指定获取后#行
  -# 同上
  -f 跟踪显示文件fd新追加的内容,常用日志监控,相当于 --follow=descriptor,当文件删除再新建同名文 件,将无法继续跟踪文件
  -F 跟踪文件名,相当于--follow=name --retry,当文件删除再新建同名文件,将可以继续跟踪文件
  tailf 类似tail –f,当文件不增长时并不访问文件
  范例:[root@centos8 ~]#tail -3 /var/log/messages  Dec 20 09:49:01 centos8 dbus-daemon[952]: [system] Successfully activated  service "net.reactivated.Fprint" Dec 20 09:49:01 centos8 systemd[1]: Started Fingerprint Authentication Daemon. Dec 20 09:49:13 centos8 su[6887]: (to mage) root on pts/0 [root@centos8 ~]#tail -f /var/log/messages  Dec 20 08:36:40 centos8 systemd[1321]: Startup finished in 52ms. Dec 20 08:36:40 centos8 systemd[1]: Started User Manager for UID 0. Dec 20 08:47:01 centos8 systemd[1]: Starting dnf makecache... Dec 20 08:47:02 centos8 dnf[1465]: AppStream                                        213 kB/s | 4.3 kB     00:00 Dec 20 08:47:02 centos8 dnf[1465]: BaseOS                                           163 kB/s | 3.9 kB     00:00 Dec 20 08:47:04 centos8 dnf[1465]: EPEL                                             2.6 kB/s | 5.3 kB     00:02 Dec 20 08:47:09 centos8 dnf[1465]: EPEL                                             884 kB/s | 4.3 MB     00:05 Dec 20 08:47:12 centos8 dnf[1465]: extras                                           727 B/s | 1.5 kB     00:02 Dec 20 08:47:12 centos8 dnf[1465]: Metadata cache created. Dec 20 08:47:12 centos8 systemd[1]: Started dnf makecache. [root@centos8 data]#ifconfig | head -2 | tail -1                                      │        inet 10.0.0.8 netmask 255.255.255.0 broadcast 10.0.0.255  4 、按列抽取文本
  cut 命令可以提取文本文件或STDIN数据的指定列
  格式cut [OPTION]... [FILE]...
  选项
  -d DELIMITER: 指明分隔符,默认tab
  -f FILEDS:
  #: 第#个字段,例如:3
  #,#[,#]:离散的多个字段,例如:1,3,6
  #-#:连续的多个字段, 例如:1-6
  混合使用:1-3,7
  -c 按字符切割
  --output-delimiter=STRING指定输出分隔符
  范例:[root@centos8 ~]#cut -d: -f1,3-4,7 /etc/passwd  [root@centos8 ~]#ifconfig |head -n2 |tail -n1|cut -d" " -f10 10.0.0.8 [root@centos8 ~]#ifconfig |head -n2 |tail -n1|tr -s " " |cut -d " " -f3 10.0.0.8 [root@centos8 ~]#df | tr -s " "|cut -d" " -f5 |tr -dc "[0-9 ]"  0 0 1 0 5 1 15 1 [root@centos8 ~]#df | tr -s " " % |cut -d% -f5 |tr -d "[:alpha:]"   0 0 1 0 5 1 15 1   [root@centos8 ~]#df | cut -c44-46 |tr -d "[:alpha:]"   0  0  1  0  5  1  15  1  [root@centos8 ~]#cut -d: -f1,3,7 --output-delimiter="---" /etc/passwd root---0---/bin/bash bin---1---/sbin/nologin daemon---2---/sbin/nologin   cat /etc/passwd | cut -d: -f7 cut -c2-5 /usr/share/dict/words5 、合并多个文件
  paste 合并多个文件同行号的列到一行
  格式paste [OPTION]... [FILE]...
  -d 分隔符:指定分隔符,默认用TAB
  -s : 所有行合成一行显示
  范例:[root@centos8 ~]#cat alpha.log a b c d e f g h [root@centos8 ~]#cat seq.log 1 2 3 4 5 [root@centos8 ~]#cat alpha.log seq.log  a b c d e f g h 1 2 3 4 5   [root@centos8 ~]#paste alpha.log seq.log a 1 b 2 c 3 d 4 e 5 f  g  h [root@centos8 ~]#paste -d":" alpha.log seq.log  a:1 b:2 c:3 d:4 e:5 f: g: h:   [root@centos8 ~]#paste -s seq.log 1 2 3 4 5 [root@centos8 ~]#paste -s alpha.log  a b c d e f g h [root@centos8 ~]#paste -s alpha.log seq.log a b c d e f g h 1 2 3 4 5  [root@centos8 ~]#cat title.txt  ceo coo cto [root@centos8 ~]#cat emp.txt  mage zhang wang xu [root@centos8 ~]#paste title.txt emp.txt ceo mage coo zhang cto wang  xu [root@centos8 ~]#paste -s title.txt emp.txt ceo coo cto mage zhang wang xu6、 分析文本的工具
  文本数据统计:wc
  整理文本:sort
  比较文件:diff和patch
  6.1 收集文本统计数据
  wc 命令可用于统计文件的行总数、单词总数、字节总数和字符总数
  可以对文件或STDIN中的数据统计
  常用选项
  -l 只计数行数
  -w 只计数单词总数
  -c 只计数字节总数
  -m 只计数字符总数
  -L 显示文件中最长行的长度
  范例:wc story.txt  39     237    1901 story.txt 行数   单词数   字节数  [root@centos8 ~]#ll title.txt -rw-r--r-- 1 root root 30 Dec 20 11:05 title.txt [root@centos8 ~]#ll title1.txt -rw-r--r-- 1 root root 28 Dec 20 11:06 title1.txt [root@centos8 ~]#cat title.txt  ceo mage coo zhang cto 老王 [root@centos8 ~]#cat title1.txt  ceo mage coo zhang cto wang [root@centos8 ~]#wc title.txt 3  6 30 title.txt [root@centos8 ~]#wc title1.txt 3  6 28 title1.txt  [root@centos8 ~]#wc -l title.txt  3 title.txt [root@centos8 ~]#cat title.txt | wc -l 3  [root@centos8 ~]#df | tail -n $(echo `df | wc -l`-1|bc)  devtmpfs          910220       0    910220   0% /dev tmpfs             924728       0    924728   0% /dev/shm tmpfs             924728    9224    915504   1% /run tmpfs             924728       0    924728   0% /sys/fs/cgroup /dev/sda2      104806400 4836160  99970240   5% / /dev/sda3       52403200  398580  52004620   1% /data /dev/sda1         999320  131764    798744  15% /boot tmpfs             184944       4    184940   1% /run/user/0
  6.2 文本排序sort
  把整理过的文本显示在STDOUT,不改变原始文件
  格式:sort [options] file(s)
  常用选项
  -r 执行反方向(由上至下)整理
  -R 随机排序
  -n 执行按数字大小整理
  -f 选项忽略(fold)字符串中的字符大小写
  -u 选项(独特,unique)删除输出中的重复行
  -t c 选项使用c作为字段界定符
  -k # 选项按照使用c字符分隔的# 列来整理能够使用多次
  范例:[root@centos8 data]#df | tr -s " " %|cut -d% -f5|tr -d "[:alpha:]" | sort   0 0 0 1 1 1 15 5 [root@centos8 data]#df | tr -s " " %|cut -d% -f5|tr -d "[:alpha:]" | sort -n  0 0 0 1 1 1 5 15 [root@centos8 data]#df | tr -s " " %|cut -d% -f5|tr -d "[:alpha:]" | sort -n  |tail -n1 15 [root@centos8 data]#df | tr -s " " %|cut -d% -f5|tr -d "[:alpha:]" | sort -nr 15 5 1 1 1 0 0 0  [root@centos8 data]#df | tr -s " " %|cut -d% -f5|tr -d "[:alpha:]" | sort - nr|head -n1 15  [root@centos8 data]#cut -d: -f1,3 /etc/passwd|sort -t: -k2 -nr |head -n3 nobody:65534 xiaoming:1002 mage:1001  [root@centos8 data]#cut -d" " -f1 access_log |sort -u|wc -l 201
  6.3 去重uniq
  uniq命令从输入中删除前后相接的重复的行
  格式:uniq [OPTION]... [FILE]...
  常见选项:
  -c: 显示每行重复出现的次数
  -d: 仅显示重复过的行
  -u: 仅显示不曾重复的行
  uniq常和sort 命令一起配合使用:
  范例:sort userlist.txt | uniq -c
  范例:[root@centos8 data]#cut -d" " -f1 access_log |sort |uniq -c|sort -nr |head -3    4870 172.20.116.228    3429 172.20.116.208    2834 172.20.0.222     [root@centos8 data]#lastb -f btmp-34 | tr -s " " |cut -d " " -f3|sort |uniq -c  |sort -nr | head -3   86294 58.218.92.37   43148 58.218.92.26   18036 112.85.42.201
  范例:[root@centos8 data]#cat test1.txt a b 1 c [root@centos8 data]#cat test2.txt b e f c 1 2 #取文件的共同行 [root@centos8 data]#cat test1.txt test2.txt | sort |uniq -d 1 b c #取文件的不同行 [root@centos8 data]#cat test1.txt test2.txt | sort |uniq -u 2 a e f
  6.4 比较文件
  diff 命令比较两个文件之间的区别[root@centos8 ~]#cat f1.txt  mage zhang wang xu [root@centos8 ~]#cat f2.txt  magedu zhang sir wang xu shi  [root@centos8 ~]#diff f1.txt f2.txt  1,2c1,2 < mage < zhang --- > magedu > zhang sir 4a5 > shi [root@centos8 ~]#diff -u f1.txt f2.txt  --- f1.txt 2019-12-13 21:31:30.892775671 +0800 +++ f2.txt 2019-12-13 22:00:14.373677728 +0800 @@ -1,4 +1,5 @@ -mage -zhang +magedu +zhang sir  wang  xu +shi  [root@centos8 ~]#diff -u f1.txt f2.txt > f.patch [root@centos8 ~]#rm -f f2.txt  [root@centos8 ~]#patch -b f1.txt f.patch  patching file f1.txt [root@centos8 ~]#cat f1.txt magedu zhang sir wang xu shi [root@centos8 ~]#cat f1.txt.orig  mage zhang wang xu
  注明第5行有区别(改变)
  复制对文件改变patch
  diff 命令的输出被保存在一种叫做"补丁"的文件中
  使用 -u 选项来输出"统一的(unified)"diff格式文件,最适用于补丁文件
  patch 复制在其它文件中进行的改变(要谨慎使用)
  适用 -b 选项来自动备份改变了的文件
  范例:diff -u foo.conf foo2.conf > foo.patch  patch -b foo.conf foo.patch
  范例:查看二进制文件的不同[root@centos8 data]#ll /usr/bin/dir /usr/bin/ls  -rwxr-xr-x. 1 root root 166448 May 12  2019 /usr/bin/dir -rwxr-xr-x. 1 root root 166448 May 12  2019 /usr/bin/ls [root@centos8 data]#ll /usr/bin/dir /usr/bin/ls -i 201839444 -rwxr-xr-x. 1 root root 166448 May 12  2019 /usr/bin/dir 201839465 -rwxr-xr-x. 1 root root 166448 May 12  2019 /usr/bin/ls [root@centos8 data]#diff /usr/bin/dir /usr/bin/ls Binary files /usr/bin/dir and /usr/bin/ls differ  [root@centos8 ~]#cmp /bin/dir /bin/ls /bin/dir /bin/ls differ: byte 737, line 2 [root@centos8 ~]#hexdump -s 730 -Cn 7 /bin/dir 000002da  00 00 47 4e 55 00 b0                             |..GNU..| 000002e1 [root@centos8 ~]#hexdump -s 730 -Cn 7 /bin/ls  000002da  00 00 47 4e 55 00 93                             |..GNU..| 000002e1
  以上内容由马哥教育整理,由需要详细Linux教程(视频+文档的),可点赞评论文章后,关注我私信"Linux学习"索要!

NVIDIAIntel释出新Driver,透露Windows11最新游戏特性目前Windows11系统已经进入测试阶段,已加入WindowsInsider的用户已经可以进行系统更新了。为了提升系统的体验,NVIDIA和Intel已经向Insider用户推送双Dies装入288个SM,NVIDIA下代HopperGPU首次采用MCM设计不论是CPU还是GPU厂商,一般来说都会提前规划三代以上,目前NVIDIA新一代的Ampere架构仍未布局完成,但其实下一代的GPU规划早在两年前已经同步部署中。近日,来自Twit单风扇散热Navi23绘图核心RadeonRX66006600XT8月11日上市外国媒体VideoCardZ爆料,AMD将计划于8月11日正式发布主流级RadeonRX6600与RadeonRX6600XT显卡,短身单风扇设计可用于MiniPC,性能将会超越R新一代iPhoneSE明年登场配A15处理器支持5G取代mini据NikkeiAsia报导,Apple新一代iPhoneSE有望在2022年上半年推出,将采用今年iPhone13系列同一款的A15处理器,并有QualcommX605G网络通讯模现阶段小米6使用体验分享前一段时间对小米6的喜爱之火又从心中燃起,所以在某二手平台入手了一台464的米6,550的价格确实有点高啊。不过一代钉子户小米6在目前作为备用机来说使用体验究竟怎样呢?一起来探讨一少许是多少?适量是什么量?云康宝厨房秤帮我解决难题在一家人的热切期盼下,我家二宝在预产期这天如约而至,如今我也是儿女双全凑齐了一个好字。给孩子冲奶粉的话我自然是责无旁贷。前两天还好,每次给他冲奶粉30ml就可以,只需要找好温度合适可抽拉双出水的厨房龙头用起来更方便大家好,我是手撕鲈鱼,一个上得了厅堂,进不了厨房,但却拧得动水管的汉子。最近家里厨房的水槽水龙头彻底GG了,开关那里出水比水龙头这里出水还多o()o,浪费水十分严重,大概是用了7年外媒iMac27寸2020跑分CPU比上代快20GPU快40Apple于8月4日公布2020年全新27寸iMac,这款全新一体式电脑采用第10代IntelCore处理器更快独立显示晶片AppleT2晶片。有科技网站就以Geekbench5跑Apple获得新专利竟可将TouchID和FaceID整合使用?Apple近年来为解决现在iPhone刘海屏幕问题已经下了不少功夫,由以往的专利文件中可以见到苹果设计了不少解决方案。当中有的是一直在缩小刘海面积,有的甚至是直接取消。而据多方消息翱翔海南三亚(一)畅游蜈支洲岛翱翔海南三亚畅游蜈支洲岛及时起飞海南三亚,躲过北京黄沙。当飞机起飞的那一刻,北京的天空已经是黄沙漫天,随着高度的提升,天空逐渐清晰,慢慢呈现出蓝天白云,随之而来的是身心愉悦,真是有2021补天白帽大会在京召开9月17日,面向全球白帽和技术精英的全球性安全行业大会2021补天白帽大会在北京举行。作为网络产品安全漏洞管理规定(以下简称规定)正式实施后的第一个白帽行业大会,来自监管机构安全团
iPhone13超大杯充电最高27W?选购充电器不妨看看小方糖30W要说智能手机行业里,哪个品牌的刀法最为精准的话,那么苹果绝对算的一个。苹果最新的旗舰手机iPhone13系列的机型在性能上就刀法精湛,最便宜的iPhone13mini就是阉割版的处曝RedmiK40s发布在即,RedmiK40跌至大米价创发烧纪录近段时间红米品牌的表现一直很平静,但据最新消息,他们正在准备一款高性价比的旗舰机型,十一点后就可以正式上市。根据数码闲聊站的最新消息,Redmi即将推出一款更便宜的100W快充新机无短板的旗舰折叠平板,三星GalaxyZFold35G评测作为折叠屏手机的开创厂商,三星今年一如既往地更新了他们的折叠屏系列,三星GalaxyZFold35G,这也是三星第一次将屏下摄像头技术用在了折叠屏手机之上。三星GalaxyZFol你入手iPhone系列手机历代起售价iPhone4一4999元(16GB)iPhone4s一4988元(16GB)iPhone5一5288元(16GB)iPhone5s5288元(16G阳台还挂衣物就Out了!松下变频热泵套装3ASEVEH902G让阳光回归一。前言经历了一次次装修和全套家电购买的经验,也算是颇有些成就和心得,家人和朋友在买电器的时候也喜欢让我给给建议。最近亲戚家新房交付,家电选购的重任又被派到我头上。对于家居环境来说用了半年的iPhone12突然换成小米Civi,重度体验一天后差别真大作为一名数码爱好者,笔者在年初的时候也是给媳妇儿买了款iPhone12绿色版本,当时花了有五千多,如今用了也是有半年时间了,有一说一,日常使用依然流畅自然,而且拍照方面也是比iPh随着全国省市实行限电措施,今年十一国庆节高速路上会拥堵吗?限电,影响了部分企业的生产经营国庆假期,给人们提供了外出游玩的机会零星出现的疫情,限制了人们的出行愿望。多方面限制,恐怕要让很多人在纠结和矛盾中度过即将到来的小长假了。首先,限电,马斯克68亿美元特斯拉德国超级工厂杀入大本营!大众汽车CEO将加剧欧洲内卷,建6家大型电池工厂盖世汽车讯据外媒报道,9月24日,大众汽车首席执行官HerbertDiess表示,特斯拉计划于今年晚些时候在欧洲开设的首个超级工厂将加剧德国乃至欧洲汽车行业的竞争。Diess在推特汉ev5g丹拿体验刚订完唐dmi,朋友说想买汉我就带他到4s店去看车,家里给了他五十万,但是又步想买suv,说要买性能车,然后我就带她去去看了汉,汉ev的顶配百公里3。9s,销售带他试驾了一圈,朋友苹果X苹果XS苹果XSMax哪个好?很高兴回答您的问题,我是数码领域创作者数码科技大搜索!以下建议,希望能帮到您进行选择1。首先对于处理器来说,苹果XSMax,苹果XS均采用的是A12处理器,而苹果X采用的则是A11什么气垫好用轻薄?好用的定义是什么呢?每个人的肤质不一样,对好用的定义也相应的是不一样的,我自己是偏干皮,冬天是大干皮,所以对我来说,底妆好用的大前提就是要足够保湿,粉制质不能太干,我比较喜欢自然轻