和awk差不多的功能

上面的例子中,把 root:x:0:0:root:/root:/bin/bash 重定向到cut命令里,-d表示分隔符,这里使用冒号: 作为分隔符,-f 表示字段,选择了第1,和第5个字段,

$ a=`echo root:x:::root:/root:/bin/bash | cut -d : -f ,`

shuohailhl@shuohailhl-PC /cygdrive/d
$ echo $a
root:root

例 2,只打印第一个字段field

例 5 截取指定个数的字符

shuohailhl@shuohailhl-PC /cygdrive/d
$ a=`echo root:x:::root:/root:/bin/bash | cut -c - ` // 截取第2到第5个字符 shuohailhl@shuohailhl-PC /cygdrive/d
$ echo $a
oot: shuohailhl@shuohailhl-PC /cygdrive/d
$ a=`echo root:x:::root:/root:/bin/bash | cut -c - ` // 截取第2到第7个字符 shuohailhl@shuohailhl-PC /cygdrive/d
$ echo $a
oot:x: shuohailhl@shuohailhl-PC /cygdrive/d
$ a=`echo root:x:::root:/root:/bin/bash | cut -c - ` // 截取前两个字符 shuohailhl@shuohailhl-PC /cygdrive/d
$ echo $a
ro shuohailhl@shuohailhl-PC /cygdrive/d
$ a=`echo root:x:::root:/root:/bin/bash | cut -c - ` // 截取第2个以后的 shuohailhl@shuohailhl-PC /cygdrive/d
$ echo $a
oot:x:::root:/root:/bin/bash

shell 中cut的更多相关文章

  1. shell中cut用法

    cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的. (1)其语法格式为:cut  [-bn] [file] 或 cut ...

  2. shell 中的与、或表达式

    今天总结一下linux shell中逻辑关机表达方式.逻辑与的表达: 1).if [ $xxx=a -a $xx=b ] 注:-a表示and的意思 2).if [ $xxx=a ] && ...

  3. 任督二脉之Shell中的正则表达式

    VBird说学习Linux,掌握了Shell和正则就相当于打通了任督二脉,此后能力的成长才会突飞猛进. Shell的基础学习之前已经总结了一篇博客:http://www.cnblogs.com/jyz ...

  4. shell中截取字符串的方法总结

    shell中截取字符串的方法有很多种, ${expression}一共有9种使用方法. ${parameter:-word} ${parameter:=word} ${parameter:?word} ...

  5. linux shell中的特殊符号

    该内容,均来自此网址(http://www.92csz.com/study/linux/12.htm).在下只是把那些命令的截图给去了. 你在学习linux的过程中,也许你已经接触过某个特殊符号,例如 ...

  6. shell中的函数、数组、报警系统脚本

    1.shell中的函数 函数就是把一段代码整理到了一个小单元中,并给这个小单元起一个名字,当用到这段代码时直接调用这 个小单元的名字即可.格式: function f_name() {commond} ...

  7. centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课

    centos  shell脚本编程2 if 判断  case判断   shell脚本中的循环  for   while   shell中的函数  break  continue  test 命令   ...

  8. (转)shell中各种括号的作用()、(())、[]、[[]]、{}

    shell中各种括号的作用().(()).[].[[]].{} 原文:http://www.jb51.net/article/60326.htm http://blog.csdn.net/good_h ...

  9. [转]Linux shell中的那些小把戏

    我日常使用Linux shell(Bash),但是我经常忘记一些有用的命令或者shell技巧.是的,我能记住一些命令,但是肯定不会只在特定的任务上使用一次,所以我就开始在我的Dropbox账号里用文本 ...

随机推荐

  1. CS184.1X 计算机图形学导论 HomeWork1

    最容易填写的函数就是left.输入为旋转的角度,当前的eye与up这两个三维向量 void Transform::left(float degrees, vec3& eye, vec3& ...

  2. prometheus 笔记

    前言 prometheus 是监控应用软件类似于nagios. 安装 1.官网下载prometheus-2.2.0.linux-amd64压缩包,解压,执行./prometheus即可.这里重要的是配 ...

  3. 【LeetCode】树(共94题)

    [94]Binary Tree Inorder Traversal [95]Unique Binary Search Trees II (2018年11月14日,算法群) 给了一个 n,返回结点是 1 ...

  4. HTML5:Canvas-绘制图形

    到本文的最后,你将学会如何绘制矩形,三角形,直线,圆弧和曲线,变得熟悉这些基本的形状.绘制物体到Canvas前,需掌握路径,我们看看到底怎么做. 栅格 在我们开始画图之前,我们需要了解一下画布栅格(c ...

  5. BZOJ2002 [HNOI2010] 弹飞绵羊

    LCT access完了一定splay再用!!! 悲伤= = LCT裸题 把调出去设虚点n+1即可 //Love and Freedom. #include<cstdio> #includ ...

  6. oracle for loop

    我们在Oracle存储过程中需要遍历一张表,应该怎样做.我想大多少的人第一个念头就是Cursor. 比如: create or replace procedure StudyCursor( resul ...

  7. Vue.js----更换头像不实时更新问题

    原因 导致问题的原因是缓存造成的,因为你图片变了但是读取头像的地址还会没有变化的 解决思路 所以解决的思路就是上传之后让图片地址改变,那么我们就可以在上传的时候给地址加上一个时间戳那么久可一达到目的了 ...

  8. ISO C 字符串创建算符 “#”

    使用用途: #define doit(name) pr_limits(#name, name) doit(RLIMIT_CORE); 这将由C预处理程序扩展为: pr_limits("RLI ...

  9. boost intrusive

    1. the advantages of intrusive container (1) Intrusive containers don't allocate memory dynamically. ...

  10. Mybatis的运行原理

    我们写的sql语句就在statementBuilder中. 整个mapper的信息都保存到configuration 1:根据配置文件创建SQLSessionFactory 先创建SqlSession ...