zoukankan      html  css  js  c++  java
  • Shell编程 之 字符截取命令

    1. 字段(列)提取命令:cut  [选项]  文件名

      选项:  - f  列号(提取第几列)   - d  分隔符(按照指定分隔符分割列) 

    [root@localhost sh]# cat student.txt 
    ID	Name	Gender	Mark
    1	alex	  male	  11
    2	boby	  male	  22
    3	cyan	  male	  33
    4	dauge	male	  44
    [root@localhost sh]# cut -f 2 student.txt   # -f 设置列号
    Name
    alex
    boby
    cyan
    dauge
    [root@localhost sh]# cut -f 2,4 student.txt 
    Name	Mark
    alex	  11
    boby	  22
    cyan	  33
    dauge	44
    [root@localhost sh]# grep "/bin/bash" /etc/passwd | grep -v "root"  # -v 取反
    user1:x:502:502::/home/user1:/bin/bash
    user2:x:503:503::/home/user2:/bin/bash
    [root@localhost sh]# grep "/bin/bash" /etc/passwd | grep -v "root" | cut -f 1 -d ":"  # -d 设置分隔符

    2. 格式化输出命令:pritf   '输出类型  输出格式'  输出内容

      

      

    [root@localhost sh]# cat student.txt 
    ID	Name	Gender	Mark
    1	alex	male	11
    2	boby	male	22
    3	cyan	male	33
    4	dauge	male	44
    [root@localhost sh]# printf '%s	%s	%s	%s
    ' $(cat student.txt)
    ID	Name	Gender	Mark
    1	alex	male	11
    2	boby	male	22
    3	cyan	male	33
    4	dauge	male	44

    3. awk 命令

      

      

      

      

      

    4. sed 命令

      

      

      

      

      

      

      

  • 相关阅读:
    python类的__repr__方法
    元素定位之css选择器(1)
    selenium-find_element相关内容
    selenium-模块概述(1)
    元素定位之css选择器(2)
    css笔记
    html笔记
    html、css、javascript之间的关系
    去除提示“Chrome正在受到自动软件的控制”
    Python3+RobotFramework+pycharm环境搭建
  • 原文地址:https://www.cnblogs.com/wnzhong/p/6388354.html
Copyright © 2011-2022 走看看