• <output id="aynwq"><form id="aynwq"><code id="aynwq"></code></form></output>

    <mark id="aynwq"><option id="aynwq"></option></mark>
  • <mark id="aynwq"><option id="aynwq"></option></mark><label id="aynwq"><dl id="aynwq"></dl></label>
  • 學習啦>學習電腦>操作系統>Linux教程>

    程序員都應該知道什么Linux命令

    時間: 春健736 分享

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”

      程序員都應該知道什么Linux命令?每個程序員,在職業生涯的某個時刻,總會發現自己需要知道一些Linux方面的知識。學習啦小編分享了程序員都應該知道的8個Linux命令,希望對大家有所幫助。

      程序員都應該知道的8個Linux命令

      我們以一些文本舉例。假設我們有2個文件,里面有訂單關于第三方的放置地點和發送回應。

      cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      cat order.in.log

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      cat

      –追加文件并在標準輸出上打印

      jfields$ cat order.out.log

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      正如他的名字所說的,你可以串聯多個文件

      jfields$ cat order.*

      8:22:20 111, Order Complete

      8:23:50 112, Order sent to fulfillment

      8:24:20 113, Refund sent to processing

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      看到效果了,但我們可以提高其可讀性。

      sort

      –對文本文件進行行排序,這里使用排序是不錯的選擇

      jfields$ cat order.* | sort

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:22:20 111, Order Complete

      8:23:45 112, 1, Joy of Clojure, Hardcover, 29.99

      8:23:50 112, Order sent to fulfillment

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      上面顯示了我們想要看到的效果,但是這只是小文件。而真實的數據是很大的,有些是你不想要的數據怎么辦?

      grep

      grep, egrep, fgrep–進行匹配輸出

      假設我只關心給PofEAA的訂單,使用grep就可以做到。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      假設訂單113里面發生了一些問題,你想看到關于113的所有訂單信息。沒錯,grep能幫你。

      jfields$ cat order.* | sort | grep “:\d\d 113, ”

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:20 113, Refund sent to processing

      你會發現在表達式里面不止有113,這是因為113也可能出現在價格里面,或者產品里面,這樣做是嚴格限制其查找結果。

      現在我們已經發出退貨訂單的信息,我們每日也要給會計發送銷售統計。他們要求每個PofEAA的項目,但他們只關心數量和價格,我們要把

      不需要的部分刪減掉。

      cut

      –從文件的每一行刪除一部分

      還是要先使用grep。

      jfields$ cat order.* | sort | grep Patterns

      8:22:19 111, 1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      8:24:19 113, -1, Patterns of Enterprise Architecture, Kindle edition, 39.99

      jfields$ cat order.* | sort | grep Patterns | cut -d”,” -f2,5

      1, 39.99

      -1, 39.99

      我們已經減少了數據,讓會計一目了然。

      假設會計想要把訂單ID做為參考,把它放在每一行的最后,并用單引號。

      sed

      –流編輯器。用來處理文本轉換。

      下面的示例演示怎樣使用它來做到我們想要的數據。

      jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”\2, ‘\1′”/

      1, Patterns of Enterprise Architecture, Kindle edition, 39.99, '111′

      -1, Patterns of Enterprise Architecture, Kindle edition, 39.99, '113′

      lmp-jfields01:~ jfields$ cat order.* | sort | grep Patterns \

      >| sed s/”[0-9\:]* \([0-9]*\)\, \(.*\)”/”\2, ‘\1′”/ | cut -d”,” -f1,4,5

      1, 39.99, '111′

      -1, 39.99, '113′

      這是一個正則表達式,但沒什么復雜的。做以下事情

      1.刪除時間

      2.捕獲訂單號

      3.刪除逗號和訂單號后面的空格

      4.捕獲此行的其余部分

      一旦我們看到了我們需要的數據,可以使用\1&\2讓輸出數據符合我們的格式要求。

      uniq

      –去除重復行

      下面的示例演示如何grep的唯一相關的交易,削減不必要的信息,并獲得計數。

      jfields$ cat order.out.log | grep “\(Kindle\|Hardcover\)” | cut -d”,” -f3 | sort | uniq -c

      1 Joy of Clojure

      2 Patterns of Enterprise Architecture

      jfields$ cat order.out.log | grep “\(Kindle\|Hardcover\)” | cut -d”,” -f3 | sort | uniq

      Joy of Clojure

      Patterns of Enterprise Architecture

      find

      –在目錄里找文件

      假設這2個文本文件存在于我們的主目錄,我們不必知道他們的全名。

      jfields$ find /Users -name “order*”

      Users/jfields/order.in.log

      Users/jfields/order.out.log

      當然還有很多選項,但99%的情況下我這么做。

      less

      –在一個文件里面向前向后移動

      讓我們回到最簡單的cat|sort的例子。你可以向前搜索使用”/”,向后使用”?”,2者都可以使用正則表達式。

      jfields$ cat order* | sort | less

      你可以試試/113.*,這將突出顯示訂單113。你可以使用?.*112,也將突出顯示訂單112,你可以用'q'退出。

     

    看過“程序員都應該知道什么Linux命令”的人還看了:

    1.linux下free命令使用方法

    2.Linux下nl命令怎么用

    3.Linux命令如何連接

    4.Linux下traceroute命令怎么用

    5.mv命令怎么用

    6.11個很有用的Linux 命令

    , ‘ class="main">