zoukankan      html  css  js  c++  java
  • 文本处理工具作业

    1、显示/proc/meminfo文件中以大小s开头的行(要求:使用两种方法)

    1 方法一:cat /proc/meminfo |grep -i ^s
    2 方法二:cat /proc/meminfo |grep ^[sS]

     

    2、显示/etc/passwd文件中不以/bin/bash结尾的行

    1 cat /etc/passwd | grep -v /bin/bash

    3、显示用户rpc默认的shell程序

    1 方法一:cat /etc/passwd |grep "^rpc" |cut -d: -f7
    2 方法二:getent passwd rpc |cut -d: -f7

    4、找出/etc/passwd中的两位或三位数

    1 cat /etc/passwd |grep "[0-9]{2,3}"

    5、显示CentOS7/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面存非空白字符的行

    1 cat /etc/grub2.cfg |egrep "^[[:space:]]+[[:graph:]].*"

    6、找出"netstat -tan"命令的结果中以'LISTEN'后跟任意多个空白字符结尾的行

    1 netstat -tan |grep "LISTEN[[:space:]]+$"

    7、显示CentOS7上所有系统用户的用户名和UID

    1 方法一:getent passwd |cut -d: -f1,3 |grep -v root |grep "[[:digit:]]{1,3}$"
    2 方法二:getent passwd |cut -d: -f1,3 |grep -ve root -e "[[:digit:]]{4,}"

    8、添加用户bash、testbash、basher、sh、nologin(其shell为/sbin/nologin),找出/etc/passwd用户名同shell名的行

    1 cat /etc/passwd |grep -o "^(.+).*1$"

    9、只利用df、grep和sort,取出磁盘各分区利用率,并从大到小排序

    1 df |grep sd |grep -Eo "[0-9]{1,3}%" |sort -nr

    10、显示三个用户root、mage、wang的UID和默认shell

    1 cat /etc/passwd |egrep "^(root|mage|wang)" |cut -d: -f3,7

    11、找出/etc/rc.d/init.d/functions文件中行首为某单词(包括下划线)后面跟一个小括号的行

    1 方法一:cat /etc/rc.d/init.d/functions |grep -o "^.*[[:graph:]]()"
    2 方法二:cat /etc/rc.d/init.d/functions |egrep "^.*[^[:space:]]()"
    3 方法三:cat /etc/rc.d/init.d/functions |egrep -o "^.*>()"

    12、使用egrep取出/etc/rc.d/init.d/functions中其基名

    1 echo /etc/rc.d/init.d/functions | egrep -o "[^/]+/?$"

    13、使用egrep取出上面路径的目录名

    1 方法一:echo /etc/rc.d/init.d/functions | egrep -o "^/.*/"
    2 方法二:echo /etc/rc.d/init.d/functions |egrep -o ".*/." |egrep -o ".*/" /etc/rc.d/init.d/

    14、统计last命令中以root登录的每个主机IP地址登录次数

    1 last |grep ^root |egrep -o "([0-9]{1,3}.){3}[0-9]{1,3}" |sort |uniq -c

    15、利用扩展正则表达式分别表示0-9、10-99、100-199、200-249、250-255

    1  [0-9]                       0-9
    2  [0-9]{2}                    10-99 
    3  [1][0-9]{2}                 100-199
    4  [2][0-4][0-9]               200-249
    5  [2][5][0-5]                 250-255

    16、显示ifconfig命令结果中所有IPv4地址

    1 ifconfig | egrep -o "<(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4]0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])>"

    17、将此字符串:welcome to magedu linux 中的每个字符去重并排序,重复次数多的排到前面

    1 echo "welcome to magedu linux" |grep -o "." |sort |uniq -c |sort -nr 

    作者:珂儿吖

    出处:http://www.cnblogs.com/keerya/

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    大家写文都不容易,希望尊重劳动成果哟~

  • 相关阅读:
    Azure PowerShell (2) 修改Azure订阅名称
    Windows Azure Platform Introduction (11) 了解Org ID、Windows Azure订阅、账户
    Azure PowerShell (3) 上传证书
    Azure PowerShell (1) PowerShell入门
    Windows Azure Service Bus (2) 队列(Queue)入门
    Windows Azure Service Bus (1) 基础
    Windows Azure Cloud Service (10) Role的生命周期
    Windows Azure Cloud Service (36) 在Azure Cloud Service配置SSL证书
    Android studio 使用心得(一)—android studio快速掌握快捷键
    android 签名、混淆打包
  • 原文地址:https://www.cnblogs.com/keerya/p/7254091.html
Copyright © 2011-2022 走看看