在生物信息领域的日常工作和学习中,我们会经常使用Bash对文件进行简单的操作,这里分享一些常用技巧。
让你处理文件更加得心应手~
导师再也不用担心你处理数据了~(并不)
_(:з」∠)_
- 找到文件的最大值
sort -t$'t' -k2 -n test.txt | tail -1
2. 找到文件的最小值 sort -t$'t' -k2 -n test.txt | head -1
3. 找到文件的中间值
cat count.txt | grep -v "count" | grep -v "NA" | wc -l # 比如有103行
cat count.txt | grep -v "count" | grep -v "NA" | head -52 | tail -1
4. sort name.scv |uniq -c
。”-c“–»“count” ,用于计算每个不重复元素的数目。如果下次让你统计不同的元素各出现了多少次,就可以这么用了!OMG!比Excel计数快多了好吗?
5. 翻看过去的代码:history
–» This bash tool prints your recently used commands on your terminal screen. (Pro tip: try it with grep
! E.g. history |grep 'cut'
will list all the commands you have used that contained cut
.)
6. 清屏,clear
7. csvkit
Excel表格处理实用工具 # 注意使用时可能会因为pandas报错,但不会对使用产生影响
8. 比较字符串是否相等
# 判断字符串是否相等,=
# 不相等就是!=
if [ "$A" = "$B" ] # 注意 [ ] 和 "$A" "$B" 中间有空格
then
echo "[ A=B ]"
else
echo "[ A!=B ]"
fi
9. 如何找到空文件夹:find ./dir -type d -empty
10. for i in ${a[@]}
遍历a数组里面所有元素
温馨提醒:只看不敲代码,是没有办法记住的。一定要动手动手动手!
如果觉得有用记得点赞鼓励我一下哟~
查看更多:
梨酱:[Linux 1]Shell“ 多线程”,提高工作效率zhuanlan.zhihu.com