1. 取出2nd 和7th 字母
cut -c2,7
2. 取出2nd - 7th字母
cut -c 2-7
也可以
cut -c -7
cut -c 2-
3. 按tab分割
cut -d $'\t' -f1-3
4. head / tail 命令
head -n 22 | tail -n 11
5. tr 命令
tr "()" "[]"
用[] 取代 ()
6. tr 删除 (删除小写字母)
tr -d a-z
7. 压缩重复字符
tr -s " "
Sort
对数值类排序
sort -n
sort -h
逆序
sort -r
按某一列排序
sort -k2
Uniq
uniq -c # 返回uniq 和 count
uniq -c -i | cut -c7- # 返回unique, count, 忽略大小写
uniq -u # 返回unique (无重复)
paste
paste -s -d";" # 练成一整行
paste -d ";" - - - # 用;分割,每三行
paste - - - # 每三行练成一整行
参考
https://coderinme.com/linux-shell-bash-concepts-hackerrank-solution/