<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      文本提取工具(查看文本)

      文本分析工具

      文本操作工具

      1、文本提取工具
      1. cat、more、less查看文本內容

      • cat:打印一個或多個文件到標準輸出

       1 #合并文件
       2 [root@example tmp]# cat file1.txt file2.txt > file3.txt
       3 
       4 #查看文件行號
       5 [root@example tmp]# cat -n /tmp/passwd | grep 12
       6 
       7 #查看文件中是否存在特殊字符
       8 [root@example tmp]# cat -A test.txt 
       9 #!/bin/bash$
      10 cat >> err.txt <<EOF$
      11 hostname:example.com$
      12 cpu:2h$
      13 mem:4096M$
      14 ip:192.168.200.154.111$
      15 EOF$
      • more:瀏覽文件內容,每次只看一頁

      • less:瀏覽文件內容,每次只看一頁

        • -/text:搜索text

        • -n/N:跳轉到next/previous匹配的地方

        • -v:用文本編輯器打開該文件

        • man命令中是采用less來分頁的

      1. head、tail過濾文本內容

      • head:顯示文件的起始10行

        • 使用 -n選項指定顯示的行

      • tail:顯示文件最后10行

        • 使用-n選項指定顯示的行

        • 使用-f選項將文件末尾追加的內容顯示在當前終端

          • 對于監控日志文件非常有用

        如果需要在指定文本中取出內容(以行取)

        • 先用head取出最大行

        • 然后用 tail 減掉所需行數

      1. grep 文本過濾工具

        • -o:顯示所有關鍵字

        • -i:忽略大小寫

        • -n:顯示行號

        • -c:顯示行數

        • -v:顯示不匹配的行(取反)

        • -q:靜默模式,沒有任何輸出,得用 $? 來判斷執行是否成功,即有沒有過濾到想要的內容

        • -AX:將匹配行及其后X行一起顯示

        • -BX:將匹配行及其前X行一起顯示

        • -CX:將匹配行及其前后X行一起顯示

        • -r:遞歸搜索目錄,根據文本內容搜索文件

        • -l:如果匹配成功,則只將文件名打印出來,失敗則不打印,通常 -rl 一起用;例如:grep -rl ‘root’ /etc

        • –color=auto:用color顏色高亮顯示匹配的數據

       1 #過濾關鍵字
       2 [root@example tmp]# grep root passwd 
       3 root:x:0:0:root:/root:/bin/bash
       4 operator:x:11:0:operator:/root:/sbin/nologin
       5 
       6 #顯示所有關鍵字
       7 [root@example tmp]# grep -o root passwd 
       8 root
       9 root
      10 root
      11 root
      12 
      13 #忽略大小寫
      14 [root@example tmp]# grep -i root passwd 
      15 root:x:0:0:root:/root:/bin/bash
      16 operator:x:11:0:operator:/root:/sbin/nologin
      17 
      18 #顯示行號
      19 [root@example tmp]# grep -n root passwd 
      20 1:root:x:0:0:root:/root:/bin/bash
      21 10:operator:x:11:0:operator:/root:/sbin/nologin
      22 
      23 #取反
      24 [root@example tmp]# grep -v root passwd 
      25 bin:x:1:1:bin:/bin:/sbin/nologin
      26 
      27 #0表示上一條命令執行成功
      28 [root@example tmp]# grep -q root passwd 
      29 [root@example tmp]# echo $?
      30 0
      31 #1表示上一條命令執行失敗
      32 [root@example tmp]# echo $?
      33 1
      34 
      35 [root@example var]# grep -A4 ftp passwd
      36 [root@example var]# grep -B4 ftp passwd
      37 [root@example var]# grep -C4 ftp passwd
      38 
      39 [root@example var]# grep -rl passwd /etc
      40 /etc/nsswitch.conf.bak
      41 /etc/login.defs
      42 /etc/security/pwquality.conf
      43 
      44 [root@example var]# alias 
      45 alias cp='cp -i'
      46 alias egrep='egrep --color=auto'
      47 alias fgrep='fgrep --color=auto'
      48 #取消高亮
      49 [root@example var]# unalias grep
      50 #打開高亮
      51 [root@example var]# alias grep='grep --color=auto'
      52 [root@example var]# source /etc/profile

          4. 正則表達式

      又稱標準正則表達式,是最早的正則表達式規范,僅支持最基本的元子符集。基本正則表達式是POSIX規范制定的兩種正則表達式語法標準之一,另外一種語法標準稱為擴展正則表達式。

      1 [root@example var]# grep bash$ /etc/passwd
      2 root:x:0:0:root:/root:/bin/bash
      3 user:x:1000:1000:user:/home/user:/bin/bash
      4 zhangsan:x:1005:1006::/home/zhangsan:/bin/bash
      字符含義
      ^ 在每行的開始進行匹配
      $ 在每行的末尾進行匹配
      \ < 在字的開始進行匹配
      \ > 在字的末尾進行匹配
      . 對任何單個字符進行匹配
      [str] 對str中的任何單個字符進行匹配
      [^str] 對任何不在str中的 單個字符進行匹配
      [a-b] 對a到b之間的任何字符進行匹配
      \ 轉義字符,抑制后面的一個字符的特殊含義
      * 對前一項(item)進行0次或多次重復匹配

      grep使用擴展的正則需要使用egrep或者是grep -E

       1 [root@example etc]# egrep roo passwd
       2 root:x:0:0:root:/root:/bin/bash
       3 operator:x:11:0:operator:/root:/sbin/nologin
       4 [root@example etc]# grep -E roo+ passwd
       5 root:x:0:0:root:/root:/bin/bash
       6 operator:x:11:0:operator:/root:/sbin/nologin
       7 [root@example etc]# grep -E 'bash|user' passwd
       8 root:x:0:0:root:/root:/bin/bash
       9 qemu:x:107:107:qemu user:/:/sbin/nologin
      10 [root@example etc]# grep  -E '(roo?)' passwd
      11 root:x:0:0:root:/root:/bin/bash
      12 operator:x:11:0:operator:/root:/sbin/nologin
      13 
      14 [root@example etc]# ifconfig | grep -Eo '([0-9]{,3}\.){3}1{1}..'
      15 192.168.200.154
      16 127.0.0.1  
      17 192.168.122.1  
      18 
      19 [root@example etc]# ifconfig | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'|grep -v 255
      20 192.168.200.154
      21 127.0.0.1
      22 192.168.122.1
      23 
      24 [root@example etc]# ifconfig | grep -w inet | cut -d " " -f10
      25 192.168.200.154
      26 127.0.0.1
      27 192.168.122.1
      1. cut - 提取列或字段

      • 顯示文件指定的列或者標準輸入數據

        • cut -d: -f1 /etc/passwd; cut -d : -f1,3 passwd

        • grep root /etc/passwd | cut -d:-f7

      • -d:來指定列分隔符

      • -f: 來指定要打印的列

      • -c:指定按字符提取

        • cut -c 2-5 /usr/share/dict/words

      1. awk 以空作為默認的分隔符

      • awk -F 分隔符 ’{print $列}‘ 文件

      1 [root@example ~]# ifconfig | grep -w inet | awk -F " " '{print $2}' 
      2 [root@example ~]# awk -F : '{print $1,$3}' /etc/passwd
      3 [root@example ~]# ifconfig | grep -w inet | cut -d " " -f10
      4 [root@example ~]# ifconfig | grep -w inet | cut -d " " -f10 | cut -d . -f4 | cut -c 1-2
      5 [root@example ~]# cut -c 1-4 /etc/passwd 
      2、文本分析工具
        1. 文本統計:wc

       1 [root@example tmp]# wc passwd 
       2   48  107 2636 passwd
       3 第一列是文件的行數
       4 第二列是文件的單詞數
       5 第三列是文件的字節數
       6 [root@example tmp]# wc -l passwd 
       7 48 passwd
       8 [root@example tmp]# wc -w passwd 
       9 107 passwd
      10 [root@example tmp]# wc -c passwd 
      11 2636 passwd
      12 [root@example tmp]# wc -wc passwd 
      13  107 2636 passwd
      1. 文本排序:sort

      sort默認按照字符表的順序排序,不是按照單詞或者數字的方式排序

      • -n:以數字的方式進行排正序

      • -r:排倒序

      • -k:指定列

      • -t:指定分隔符

      • -u:去重

      • -f:忽略大小寫

      1 以數字進行排序 -n
      2 [root@example tmp]# sort -t : -k 3 -n passwd 
      3 以數字進行倒序 -r
      4 [root@example tmp]# sort -t : -k 3 -r -n passwd 
      1. 文本比較:diff

      比較文本差異,可以使用圖像化工具vimdiff

      1 [root@example tmp]# diff /etc/passwd /tmp/passwd 
      2 47a48
      3 > user2:x:1002:1002::/home/user2:/bin/bash
      4 [root@example tmp]# vimdiff /etc/passwd /tmp/passwd 
      5 2 files to edit
      3、文本操作工具
      1. 文本轉換工具:tr

      1 [root@example tmp]# tr a-z 1-2 < passwd 
      2 2222:2:0:0:2222:/2222:/222/2122
      1. 流編輯器:sed

      用來進行文本的操作;查找、替換、刪除、新增

      • 地址定界:指的是要操作的行

        • #:為數字,指定要進行處理操作的行

        • $_:表示最后一行,多個文件進行操作的時候,為最后一個文件的最后一行

        • /regexp/:表示能夠被regexp匹配到的行,regexp及基于正則表達式的匹配

        • /regexp/l:匹配時忽略大小寫

        • \%regexp%:任何能夠被regexp匹配到的行,換用%(用其它字符也可以,如:#)為邊界符號,當內容出現 \ 時使用

        • addr1,addr2:指定范圍內的所有的行(范圍選定)常用地址界表示方式

          • 0,/regexp/:從起始行開始到第一次能夠被regexp匹配到的行

          • /regexp/,/regexp/:被模式匹配到的行內地的所有的行

        • first~step:指定起始的位置及步長,例如:1 ~ 2表示1,3,5…

        • addr1,+N:指定行以及以后的N行

        • addr1,~N:指定行開始的N行

       1 [root@example tmp]# sed -n 1p passwd 
       2 root:x:0:0:root:/root:/bin/bash
       3 [root@example tmp]# sed -n 10,12p passwd 
       4 operator:x:11:0:operator:/root:/sbin/nologin
       5 games:x:12:100:games:/usr/games:/sbin/nologin
       6 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
       7 [root@example ~]# sed -n '/^root/p' /etc/passwd
       8 root:x:0:0:root:/root:/bin/bash
       9 [root@example ~]# sed -n '$p' /etc/passwd
      10 zhangsan:x:1001:1001::/home/zhangsan:/bin/bash

      地址定界的操作

      • p:打印模式空間的內容

      • d:刪除匹配到的內容

      • -i:將操作保存到文件

      • a\text:append,表示在匹配到的行之后追加內容

      • i\text:insert,表示在匹配到的行之前追加內容

      • c\text:change,表示把匹配到的行和給定的文本進行交換

      • s/regexp/replacement/flages:查找替換,把text替換為 regexp 匹配到的內容(其中/可以用其它字符代替,例如@)

      • 其它編輯命令

        • g:全局替換,默認只替換第一個

        • i:不區分大小寫

        • p:如果成功替換則打印

      • w /path/to/somefile:將匹配到的文件另存到指定的文件中

      1 [root@example ~]# sed '1d' /etc/passwd
      2 [root@example ~]# sed -i '1d' /etc/passwd
      3 [root@example ~]# sed '/ftp/i\text' /tmp/passwd 
      4 [root@example ~]# sed '/ftp/a\text' /tmp/passwd 
      5 [root@example ~]# sed '/ftp/c\text' /tmp/passwd 
      6 [root@example ~]# sed -n 's/ftp/http/p' /tmp/passwd 
      7 http:x:14:50:FTP User:/var/ftp:/sbin/nologin
      8 [root@example ~]# sed  '46,48 s/ftp/http/gip' /tmp/passwd 
      9 [root@example ~]# sed '/root/ w /tmp/zhangsan.txt' /tmp/passwd 

      注意事項:

      • 如果沒有指定地址,表示命令將應用于每一行

      • 如果只有一個地址,表示命令將應用于這個地址匹配的所有行

      • 如果指定了由逗號分隔的兩個地址,表示命令應用于匹配第一個地址和第二地址之間的行(包括這兩行)

      • 如果地址后面跟有感嘆號,表示命令將應用于不匹配該地址的所有行

       

      posted on 2023-12-14 22:20  Ju生淮北  閱讀(122)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 午夜国产精品福利一二| bt天堂新版中文在线| 国产午夜视频在线观看| 久久―日本道色综合久久| 农村熟女大胆露脸自拍| 日韩av影院在线观看| 真实单亲乱l仑对白视频| 中文字幕国产精品自拍| 国产女人喷潮视频免费 | 国内少妇偷人精品免费| 中文精品无码中文字幕无码专区| 激情五月天自拍偷拍视频| 中文字幕制服国产精品| 乌兰浩特市| 在线观看美女网站大全免费| 免费人成网站免费看视频| 乌克兰美女浓毛bbw| 国产极品精品自在线不卡| 亚洲精品综合久久国产二区| 亚洲av片在线免费观看| 亚洲大尺度无码专区尤物| www插插插无码免费视频网站| 国产第一页浮力影院入口| 少妇特殊按摩高潮惨叫无码| 亚洲AV永久中文无码精品综合| 潮喷失禁大喷水av无码| 人妻系列中文字幕精品| 久久99国产精品尤物| 和黑人中出一区二区三区| 92国产福利午夜757小视频| 亚洲综合无码AV在线观看| 精品国产一区二区亚洲人| 久久国产成人午夜av影院| 亚洲色一区二区三区四区| 国产成人精品性色av麻豆| 久久99精品久久久久久青青| 人人入人人爱| 亚洲综合久久精品哦夜夜嗨| 国产国语一级毛片| 成人污视频| 国产精品视频一区不卡|