博客
关于我
常用的shell命令(cut sed sort awk nl head …)
阅读量:722 次
发布时间:2019-03-21

本文共 769 字,大约阅读时间需要 2 分钟。

常用的Shell命令总结

  • cut(字节操作工具)
  • cut -b 2,3 test.txt #查看占用第2、3个字符的内容
    cut -c 8 test.txt #查看第8个字节的内容
    cut -nb 1- test.txt #按字节分割并逐行显示
    cut -b -1 test.txt #按字符分割
    cut -d: -f 2 test.txt #按':'分割,取第二列
  • sort(文本排序工具)
  • sort -n test.txt #按自然顺序排序
    sort -r test.txt #倒序排序
    sort -rk2 test.txt #按第二列倒序排序
    sort -rk3 test.txt #按第三列倒序排序
  • head(取出文本内容)
  • head -n 10 test.txt #取出前10行
  • awk(处理文本格式工具)
  • ps -ef | awk '{print $2}' #提取进程信息中的用户
    head -n 1 test.txt | awk 'BEGIN{FS=":"} {print$1}' #按':'分割并提取第一列
    head -n 1 test.txt | awk -F: '{print$1,$2}' #同时打印第一、二列
  • sed(文本操作工具)
  • nl sed.txt #显示行号和内容
    sed '1a motherfucker sed.txt' #在第一行后面添加文本
    sed '1i fuck you sed.txt' #在第一行前面插入文本
    sed '2,5d sed.txt' #删除第二到第五行
    sed '1,5c HELLO WORLD sed.txt' #替换第一到第五行
    sed -n '2p sed.txt' #显示第二到第五行
    sed -n '/hello/p sed.txt' #筛选含有"hello"的行

转载地址:http://yjygz.baihongyu.com/

你可能感兴趣的文章
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>