1. 程式人生 > >linux檔案管理命令之cut

linux檔案管理命令之cut

cut 命令那個用來顯示行中指定部分
語法:
Usage: cut OPTION... [FILE]...
Print selected parts of lines from each FILE to standard output.

Mandatory arguments to long options are mandatory for short options too.
  -b, --bytes=LIST        select only these bytes
  -c, --characters=LIST   select only these characters
  -d, --delimiter=DELIM   use DELIM instead of TAB for field delimiter
  -f, --fields=LIST       select only these fields;  also print any line
                            that contains no delimiter character, unless
                            the -s option is specified
  -n                      with -b: don't split multibyte characters
      --complement        complement the set of selected bytes, characters
                            or fields
  -s, --only-delimited    do not print lines not containing delimiters
      --output-delimiter=STRING  use STRING as the output delimiter
                            the default is to use the input delimiter
      --help     display this help and exit
      --version  output version information and exit

Use one, and only one of -b, -c or -f.  Each LIST is made up of one
range, or many ranges separated by commas.  Selected input is written
in the same order that it is read, and is written exactly once.
Each range is one of:

  N     N'th byte, character or field, counted from 1
  N-    from N'th byte, character or field, to end of line
  N-M   from N'th to M'th (included) byte, character or field
  -M    from first to M'th (included) byte, character or field

With no FILE, or when FILE is -, read standard input.

舉例:
 -b -c 擷取指定位元組,字元的列,如果是單位元組沒區別,如果是多位元組,比如有漢字那就不一樣了
[[email protected] ~]# cut -b 1-3 1.txt
123
123
[[email protected] ~]# cut -c 1-3 1.txt
123
123
[[email protected] ~]# cat 1.txt
123456
123456

-n用來告訴如果遇到多位元組字元時候不拆分                                
[[email protected] ~]# cut -c 1-3 1.txt
123
123
中文
[
[email protected]
~]# cut -b 1-3 1.txt 123 123 中 [[email protected] ~]# cat 1.txt 123456 123456 中文 [[email protected] ~]# cut -c 2 1.txt 2 2 文 [[email protected] ~]# cut -b 2 1.txt 2 2 [email protected] ~]# cut -nb 2 1.txt 2 2 文

-d域分隔符,-f域欄位
[[email protected] ~]# cat 1.txt
123456;union
123456;china
中文;英文
[
[email protected]
~]# cut -f1 -d";" 1.txt 123456 123456 中文 [[email protected] ~]# cut -f2 -d";" 1.txt union china 英文

--complement 選項是提取指定欄位之外的咧
[[email protected] ~]# cut -f2  -d";" --complement  1.txt
123456
123456
中文

另外: -b, -c or -f都可以使用range來限定指定的咧
[[email protected] ~]# cut -f1-2 1.txt
123456;union
123456;china
中文;英文
[[email protected] ~]# cut -f1- 1.txt
123456;union
123456;china
中文;英文
[[email protected] ~]# cut -f- 1.txt
cut: invalid range with no endpoint: -
Try 'cut --help' for more information.
[[email protected] ~]# cut -f-2 1.txt
123456;union
123456;china
中文;英文


相關推薦

linux檔案管理命令cut

cut 命令那個用來顯示行中指定部分 語法:Usage: cut OPTION... [FILE]... Print selected parts of lines from each FILE to standard output. Mandatory argument

Linux遠端管理命令網絡卡與IP地址

網絡卡 網絡卡是一個專門負責網路通訊的硬體裝置 IP地址是設定在網絡卡上的地址資訊 我們可以把電腦比作電話,網絡卡相當於SIM卡,IP地址相當於電話號碼 IP地址 每天聯網的電腦上都有IP地

Linux檔案管理命令cat用法】

[cat] 1:檢視檔案內容 (cat + 檔名) [email protected]:~#cat s.txt ~~~~~ ~~~~~ [email protected]:~# 2:建立檔案(cat + >檔名  + <<

Linux遠端管理命令關機與重啟--shutdown

shutdown命令可以安全關閉或者重新啟動系統 shutdown 選項 時間 -r 重新啟動 不指定選項和引數,預設1分鐘之後關閉電腦 遠端維護伺服器時,最好不要關閉系統,而應該重新啟動系統

Linux 檔案管理命令

Linux 檔案管理命令 1、檔案建立 touch filename 注意: touch不但可以建立檔案也可以修改檔案的時間戳 時間戳分為: atime:檔案內容被訪問的時間標識 mtime:檔案內容被修改的時間標識 ctime:檔案屬性或檔案內容被修改的時間標識 2、目錄建立 1)

linux使用者管理命令使用者修改-30

一、linux使用者管理命令passwd當用一個useradd新增完一個使用者後還需要給這個使用者設定密碼,不然是無法使用的,那麼就用到了下面的命令:1、passwd命令格式 [root@localhost ~]# passwd [選項] 使用者名稱 選項: -S 查詢

linux 位元組擷取命令cut

執行許可權:所有使用者 所在位置:/usr/bin/cut 語       法:cut options...   file... 功       能:字元擷取命令,以TAB(製表符)為預設分隔符 局

linux檔案管理小結自定義more

1.more命令功能 more命令用於檢視內容超過一屏的文字(類似於cat) 基本功能: 1.輸入backspace :內容翻一屏 2.輸入enter : 內容翻一行 3

Linux系統管理命令lastcomm的使用

今天在進行一個資訊系統的學習,其中看到一個linux系統命令以前貌似沒有使用過,就是lastcomm。於是乎抱著學習的心態,百度了一下它的相關命令引數及用法,現在分享出來供大家參考。 lastcomm是用來顯示以前用過的命令資訊。accton用來啟動程序記錄,這樣就會把所有

Linux學習檔案管理命令

1、ls命令:- list directory contents ls命令用於列出目標目錄下所有子目錄和檔案 (1)使用格式: ls [OPTION]... [FILE]... (2)option: ls -a:顯示所有檔案,包括隱藏檔案 [[email 

Linux 進程管理命令ps

Linux 進程管理命令之ps的簡單操作這個命令會顯示某一時刻系統的進程狀態。ps是通過/proc接口,讓管理員查看內核進程狀態信息。為了響應一切皆文件,進程參數模擬成文件系統類型(文件),參數路徑模擬成目錄/proc/# 每個進程都有一個進程ID號這個目錄裏存放的各種進程的狀態信息啟動進程的方式1、系統啟動

Linux 進程管理命令pidof

Linux 進程管理命令pidof的簡單提取指定進程的進程號看見了沒,pgrep可以輸入類進程名(不必輸入準確的進程名),但是pidof必須輸入正確的進程名。Linux 進程管理命令之pidof

Linux 進程管理命令pgrep

Linux 進程管理命令之pgrep簡單根據進程屬性查看指定進程信息-U 根據UID顯示進程-G 根據groupid顯示進程-t 與指定終端相關的進程-l 顯示進程名-a 顯示進程ID與啟動該進程的命令-p 顯示指定進程的子進程顯示了與zhengyue用戶相關的進程進程ID看不出進程名稱,需要使用-l參數這個

Linux 進程管理命令htop

Linux htop命令的簡單操作這個命令是top命令的增強型,這個命令需要安裝,而且需要使用EPEL的YUM源,我使用的是阿裏的源1 2 3 4分別代表4顆CPU其他的跟top命令差不多。Linux 進程管理命令之htop

Linux 進程管理命令top

Linux進程管理命令之top的簡單操作類似於Windows的任務管理器這個命令默認就可以動態的顯示進程狀態21:39:20 這個是當前時間up 15 min 是top進程的運行時間1 user 是在線用戶數load average 負載的平均值 過去1分鐘 5分鐘 15分鐘的負載值tasks 工作總數量 r

Linux 進程管理命令dstat

Linux dstat的簡單操作生成系統資源使用統計數據,這個程序也需要安裝,系統默認不自帶dstat N MN 刷新間隔M 刷新次數默認會一直刷下去這個命令很強大,運維時需要好好研究。選項 -c 顯示CPU相關信息 -C # 顯示指定哪顆CPU信息 -d 顯示磁盤的相關信息 -D 顯

Linux 進程管理命令vmstat

Linux vmstat命令的簡單操作顯示虛擬內存的統計信息r:可運行進程數 包括正在運行和準備運行的進程b:不可中斷睡眠的進程Memoryswpd swap空間的使用量free 空閑內存量buff 用於buff的內存量cache 用於cache的內存量swapsi:從disk到swap分區的量so:從swa

Linux 進程管理命令pmap

Linux pmap命令的簡單操作顯示指定進程的內存映射表這個命令僅供了解,我覺得我一輩子不會使用這個命令。這裏我只想說一件事,就是Linux的思想是一切皆文件,那麽進程對應的內存也是保存在文件系統中的,雖然/proc目錄是一個偽文件系統pmap的信息可以說是從/proc/1/maps中取出的Linux 進程

Linux 進程管理命令kill

Linux kill命令的簡單操作終止一個進程查看當前可用的信號集查看信號的名稱根據以上顯示內容,一個信號的表示方式有三個:1、編號(1、2、3) 2、簡寫(HUP) 3、全稱(SIGHUP)常用信號1、SIGHUP 無須關閉進程而讓該進程重讀配置文件 如果有多個相同進程,需要指定由root運行的進程2、SI

Linux 進程管理命令jobs

Linux jobs命令的簡單操作作業分為前臺作業和後臺作業前臺作業(foreground) 通過終端啟動,且啟動會一直占據終端。比如vim、cp後臺作業(background)可以通過終端啟動,如何讓作業運行於後臺?1、如果作業已經運行,可以使用ctl+z,但是這個命令會使得作業停止。使用kill -s 1