文件sort、cut命令
文件排序-sort
sort
Ordering a set of items according to some criteria
options
b Ignore leading blanks
f Consider lowercases and uppercase letters to be equivalent
t field separator
r Sort in reverse order
k Specify a field as the sort key
n Compare according to string numerical value
Notice the LANG!
- 對某一列排序
默認是以空格劃分
sort -k index file
index 爲文件中的列
把該列當作字符來比較
2. 把該列當作數字來比較
-n
sort -nk -4 file
3.逆序
-r
sort -rnk -4 file
4.字段分隔符
指定分隔符 -t
[s14516@gdufs]$sort -t: -nk4 /tmp/student_record
對於排序,要注意文件的語言
echo $LANG
cut 定位符
1.默認分隔符爲定位符
cut -f1 a.txt
f1 爲分隔後的第一個位置的值
2. 指定字段分隔符
cut -d" " -f1 a.txt
[s14516@gdufs]$cut -d":" -f1 /tmp/donors
3.截取指定位置的字符
cut -c11-19 f a.txt