常用shell命令

來源:互聯網
上載者:User

標籤:

1.搜尋

grep -lr yhb ./

表示在目前的目錄的所有檔案包括子檔案中搜尋yhb這個字元,並且把所在的檔案名稱列印出來。如果沒有-l,則會把搜尋到的行列印出來。

 

2.顯示行數

nl test.txt

預設顯示出非空行的行號。

nl -b a test.txt

顯示出所有行的行號,包括空行。

nl test.txt | wc -l

統計非空行數

 

3.sed命令

  • 選擇文本: -n 不顯示預設緩衝區的內容,-p 強制顯示出緩衝區的內容    sed -n ‘1,3p‘ students.txt  #只顯示1~3行
  • 替換文本: [address1[,address2]] s/pattern/replacemen/[flag]      sed ‘1,3 s/e/E/g‘ students.txt #替換1~3行中的所有的小寫字母e為大寫字母E
  • 刪除文本: [address1[,address2]]  d       sed ‘1,4 d‘ students.txt #刪除1到4行   sed ‘/^$/ d‘ students.txt  #刪除空行
  • 插入文本: [address1]  i string               sed ‘2 i 200200109 Tom‘ students.txt #在第二行插入200200109 Tom 記錄。

 

常用shell命令

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.