cut命令
作用:從文件的每一行剪切字節,字符或者字段,類似與編程語言中的字符串截取函數
格式:cut [option] [file]
-b:僅顯示行中指定直接范圍的內容;
-c:僅顯示行中指定范圍的字符;
-d:指定字段的分隔符,默認的字段分隔符為“TAB”;
-f:顯示指定字段的內容;
-n:與“-b”選項連用,不分割多字節字符;
N-:從第N個字節、字符、字段到結尾;
N-M:從第N個字節、字符、字段到第M個(包括M在內)字節、字符、字段;
-M:從第1個字節、字符、字段到第M個(包括M在內)字節、字符、字段。
ghostwu@dev:~/linux/cut$ cat ghostwu.txt hello,this is ghostwu how are you ghostwu@dev:~/linux/cut$ cut -b 1 ghostwu.txt h h ghostwu@dev:~/linux/cut$ cut -b 1-3 ghostwu.txt hel how ghostwu@dev:~/linux/cut$ cut -b 1-2,4-5 ghostwu.txt helo ho a ghostwu@dev:~/linux/cut$ cut -b 1- ghostwu.txt hello,this is ghostwu how are you ghostwu@dev:~/linux/cut$ cut -b -1 ghostwu.txt h h
截取/etc/passwd第一列
cut -d : -f 1 /etc/passwd