Bash字符串处理(与Java对照) - 19.查找字符的位置

Bash字符串处理(与Java对照) - 19.查找字符的位置

In Java

String.indexOf & String.lastIndexOf

 int     indexOf(int ch)
          返回指定字符在此字符串中第一次出现处的索引。
 int     indexOf(int ch, int fromIndex)
          从指定的索引开始搜索,返回在此字符串中第一次出现指定字符处的索引。

 

int     lastIndexOf(int ch)
          返回最后一次出现的指定字符在此字符串中的索引。
 int     lastIndexOf(int ch, int fromIndex)
          从指定的索引处开始进行后向搜索,返回最后一次出现的指定字符在此字符串中的索引。

 

StringUtils.indexOf & StringUtils.indexOfAny & StringUtils.indexOfIgnoreCase & StringUtils.lastIndexOf

在 org.apache.commons.lang.StringUtils 中提供了很多查找字符索引的方法,包括正向和反向。

 

static int     indexOf(String str, char searchChar)
          Finds the first index within a String, handling null.
static int     indexOf(String str, char searchChar, int startPos)
          Finds the first index within a String from a start position, handling null.

static int     lastIndexOf(String str, char searchChar)
          Finds the last index within a String, handling null.
static int     lastIndexOf(String str, char searchChar, int startPos)
          Finds the last index within a String from a start position, handling null.

 

在 org.apache.commons.lang.StringUtils 中还提供了查找任意字符出现的位置的方法。
static int     indexOfAny(String str, char[] searchChars)
          Search a String to find the first index of any character in the given set of characters.
static int     indexOfAny(String str, String searchChars)
          Search a String to find the first index of any character in the given set of characters.
static int     indexOfAnyBut(String str, char[] searchChars)
          Search a String to find the first index of any character not in the given set of characters.
static int     indexOfAnyBut(String str, String searchChars)
          Search a String to find the first index of any character not in the given set of characters.

 

In Bash

使用遍历字符的方式来查找字符的位置

函数:strchr <str> <ch>

如果找到,打印字符的位置,从0开始计数,退出码为0;否则打印-1,退出码为1

strchr(){
    local i
    for ((i=0; i<${#1}; ++i))
    do
        if [ "${1:i:1}" == "$2" ]; then
            echo $i
            return 0
        fi
    done
    echo -1
    return 1
}

 

[root@web ~]# STR=123456789
[root@web ~]# CH=6
[root@web ~]# strchr "$STR" "$CH"
5
[root@web ~]# echo $?
0
[root@web ~]# CH=a
[root@web ~]# strchr "$STR" "$CH"
-1
[root@web ~]# echo $?
1
[root@web ~]#

 

用expr index来查找字符的位置

格式:expr index "$STR" "$CHARS"

在STR中查找CHARS中的任何字符(而不是子串),打印第一个位置。

注意:返回的下标是从1开始的,0表示没有找到。

不完全对应于Java的indexOf方法。倒是与C++ STL string的find_first_of相似。

 

man expr 写道
index STRING CHARS
   index in STRING where any CHARS is found, or 0

 

[root@jfht ~]# STR="Hello World"
[root@jfht ~]# SUB="l"
[root@jfht ~]# expr index "$STR" "$SUB"
3

[root@jfht ~]# SUB="not found"      # 注意,expr index并不能用能查找子串的位置,而是该字符串中任何字符首次出现的位置
[root@jfht ~]# expr index "$STR" "$SUB"
5

 

用awk index来查找字符出现的位置

格式1:awk -v "STR=$STR" -v "CH=$CH" '{print index(STR,CH)}' <<<""

格式2:echo | awk -v "STR=$STR" -v "CH=$CH" '{print index(STR,CH)}'

因为awk默认会从标准输入读取数据,所以必须进行输入的重定向。

此方法不仅可以查询字符的出现位置,也可以查询子串的出现位置。但不能查找任意字符的出现位置。

注意:索引位置从1开始计数,0表示没有找到。

man awk 写道
index(s, t) Returns the index of the string t in the string s, or 0 if t is not present. (This
implies that character indices start at one.)
 

[root@web ~]# STR=123456789
[root@web ~]# CH=6

[root@web ~]# awk -v "STR=$STR" -v "CH=$CH" '{print index(STR,CH)}' <<<""
6
[root@web ~]# echo | awk -v "STR=$STR" -v "CH=$CH" '{print index(STR,CH)}'
6
[root@web ~]#

 

 

本文链接:http://codingstandards.iteye.com/blog/1198917  (转载请注明出处)

返回目录:Java程序员的Bash实用指南系列之字符串处理(目录) 

上节内容:Bash字符串处理(与Java对照) - 18.格式化字符串

下节内容:Bash字符串处理(与Java对照) - 20.查找子串的位置

 

 

在hyper-v管理器中修改WSL虚拟交换机后,打开wsl闪退 此次是因为修改了WSL虚拟交换机造成的wsl打不开或闪退,还有一种可能是关闭了hyper-v造成了wsl。 阅读详情

相关推荐

LTE信令流程实战:从Attach到Service Request的完整解析(附常见问题排查)

本文深入解析LTE信令流程中的Attach和Service Request关键环节,提供从基础原理到实战排查的完整指南。涵盖鉴权、承载建立等核心步骤,分析常见故障模式及优化方案,并附赠信令跟踪工具使用技巧,助力通信工程师提升网络运维效率。

alpha的博客 319

JAVA中String类常见的几种查找字符方法

String类简介: 在JAVA中String是一个引用数据类型默认为null,String为final修饰值在创建后不能更改,类型且是线程安全的不能被继承,但可以被线程共享 引入大佬博客 而String类中给我们提供了许多查找的方法,接下来我会盘点几种比较常用的String类查找方法,欢迎点赞收藏您的关注就是我的动力 :-) ...

T2827813408的博客 1万+

Zotero插件安装保姆级教程:从Jasminum到Sci-Hub,一站式搞定文献管理

本文提供Zotero插件安装的保姆级教程,从Jasminum到Sci-Hub,一站式搞定文献管理。通过详细配置和实战案例,帮助用户高效构建文献工作流,提升研究效率。重点介绍了元数据抓取、PDF管理、文献分析和知识产出等关键插件的使用方法。

weixin_42531516的博客 169

java indexof查找中文,Java indexOf() 方法

Java indexOf() 方法indexOf() 方法有以下四种形式:public int indexOf(int ch): 返回指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。public int indexOf(int ch, int fromIndex): 返回指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。int in...

weixin_39941721的博客 1034

PCB铺铜技巧如何铺铜经验总结

铺铜是指在PCB电气层添加整块的铜皮;铺铜包括电源层铺铜,地层铺铜和信号走线层空闲区域铺铜;铺铜是PCB设计的一个重要的环节。

fydar的博客 1万+

Ubuntu零基础教学-如何把Ubuntu20.04界面从英文修改为中文?| 超级详细,建议收藏

带你如何把Ubuntu20.04界面从英文修改为中文?| 超级详细,建议收藏

**My Coding Family** 5338

indexof java_Java中indexOf的用法

indexOf有四种用法:1.indexOf(int ch) 在给定字符串中查找字符(ASCII),找到返回字符数组所对应的下标找不到返回-12.indexOf(String str)在给定符串中查找另一个字符串。。。3.indexOf(int ch,int fromIndex)从指定的下标开始查找某个字符,查找到返回下标,查找不到返回-14.indexOf(String str,int from...

weixin_28904519的博客 1698

把 SAP Activate 六个阶段看透:从项目落地到 SAP BTP 扩展与 AI 运营的一体化实践

摘要: SAP Activate 方法论常被误解为简单的项目阶段划分,实则是一套将业务目标、标准流程、系统配置和持续运营串联的实施控制体系。其六个阶段(Discover至Run)构成价值递进的实施通道,核心交付集中在Prepare到Deploy阶段。Discover阶段通过DDA评估确立项目方向与范围,Prepare阶段聚焦可执行性准备,Explore阶段采用Fit-to-Standard工作坊进行需求分层,Realize阶段基于前期决策进行配置与扩展开发。该方法论强调标准化优先,差异化需求通过SAP BT

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2329

bash字符串操作

基于字符处理:${#var}:返回字符串长度${var:offset}:返回字符串变量var中从第offset个字符后(不包括第offset个字符)的字符到最后的部分,offset的取值在0到${#var}-1之间。(bash-4.2后允许为负值)。${var:offset:number}:返回字符串变量var中从第offset个字符后(不包括第offset个字符)的字符开始,长度为number的部

Joah_li的博客 485

40.8K星爆火!Crawl4AI实战突破Cloudflare 5秒盾:AI反爬新范式,爬虫再也不被封

Crawl4AI的爆火(40.8K星)不是偶然——它解决了爬虫工程师最头疼的反爬问题,让爬虫从“体力活”变成“脑力活”,不用再花费大量时间配置指纹、编写行为脚本。但要注意:爬虫必须遵守目标网站的robots.txt协议,不得用于非法爬取数据(比如用户隐私、商业机密)。合理使用技术,才能长久落地。如果你在使用Crawl4AI时遇到具体问题(比如绕过更严格的反爬、批量爬取配置),欢迎在评论区交流,我会第一时间分享解决方案!

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1603

Linux 配置 multipath 多路径

每天一个 DBA 小知识,助你更进一步!

LuciferLiu_DBA 3296

高级Bash脚本编程指南(15):循环

高级Bash脚本编程指南(15):循环 成于坚持,败于止步 循环就是迭代(重复)一些命令的代码块, 如果循环控制条件不满足的话, 就结束循环. for循环 for arg in [list] 这是一个基本的循环结构. 它与C语言中的for循环结构有很大的不同. for arg in [list] do command(s)... done在循环的每次执行中, arg将顺序

Seal--学海无涯 2887

Hindsight 内存爆炸 4 个词排查清单:9,284 条 6 成是 SSH 调试日志——Agent 标签系统的实战复盘

9,284 条记忆里 66% 是 SSH 调试日志。4 个标签被滥用=0 区分度。3 个 entity_labels + retain_mission + retain_every_n_turns 配置把噪声压回 5%——附 PATCH 脚本和实测前后数据。

Starry-SkyJing的博客 57

Bash字符串处理(与Java对照) - 20.查找子串的位置

Bash字符串处理(与Java对照) - 20.查找子串的位置 In Java String.indexOf  int     indexOf(String str)           返回第一次出现的指定子字符串在此字符串中的索引。  int     indexOf(String str, int fromIndex)           从指定的索引处开始,返回第...

巨人站在肩膀上 328

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

【Linux】Shell 脚本中的字符串处理技巧

本文介绍了Shell脚本中的字符串处理技巧,包括字符串定义与赋值、长度计算、截取与切片等基础操作,并通过密码强度检查和文件路径处理等实战案例展示了这些技巧的应用。文中还提供了对应的Java代码示例,便于开发者对比理解不同语言中的字符串处理方式。文章内容实用,适合Shell脚本初学者和进阶开发者学习参考。

千淘万漉虽辛苦,吹尽狂沙始到金 2万+

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Java程序员的Bash实用指南系列之字符串处理(目录)

Java程序员的Bash实用指南系列之字符串处理(目录) 文章   在一般的计算机编程语言中,字符串处理是很重要的一块,Bash也是如此,如果掌握了字符串的处理,基本上就能够应付大部分的编程工作了。在Unix/Linux操作系统中,很多时候需要使用多个命令一起配合才能完成一个较复杂的任务,Shell提供了管道线、重定向、结构化编程等方式,把这些命令粘合在一起。因此,命令之间的接口数据的处理

Nicholas的专栏 QQ1295794532 1139

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

linux通过java服务名查找所在位置

我整理的一些关于【Java】的项目学习资料(附讲解~~)和大家一起分享、学习一下:https://d.51cto.com/bLN8S1在Linux中通过Java服务名查找所在位置 在现代软件开发中,了解如何查找服务位置是一项重要技能。本文将引导您通过一个简单的实例,使用Java在Linux系统中通过服务名查找其所在位置。...

weixin_36755640的博客 208

[linux] shell 变量 字符串 数组

变量 定义变量时,变量名不加美元符号$ your_name="qm" #变量名和等号之间不能有空格 变量名的命名须遵循如下规则: 首个字符必须为字母(a-z,A-Z)。 中间不能有空格,可以使用下划线(_)。 不能使用标点符号。 不能使用bash里的关键字(可用help命令查看保留关键字)。 除了显式地直接赋值,还可以用语句给变量赋值,如: for fil...

aefg95955的博客 986

linux 判断相等,linux if 判断字符串是否相等

str1==str2和str1.Equals(str2)。两种方法都可以。#!/bin/shecho -n "login:"read nameecho -n "password:"read passwdif [ "$name" = "aa" -a "$passwd" = "aaa" ];thenecho "right!"else echo "error"fi一。运行过程中出现过[: mi...

weixin_29284885的博客 4708

php字符串去掉空,php去掉字符串空

PHP对表单提交特殊字符的过滤和处理函数名释义介绍htmlspecialchars将与、单双引号、大于和小于号化成HTML格式&转成&amp;"转成&quot;' 转成&#039;<转成&lt;>转成&gt;htmlentities()所...文章科技小能手2017-11-121015浏览量【PHP】字符串去空格并将每个单词首字母转换成大...

weixin_39830225的博客 517

shell编程(编写、执行,shell变量、传参、字符串、运算符使用)

不会shell真的烦,生产运维总添乱。一文带你从小白顺利入门shell脚本编程。文章包含shell脚本的编写与执行,还有shell变量、传参、字符串、运算符的使用方法和总结。

引用原创内容标明出处即可 2436

Shell脚本之二 变量、字符串和数组

一、Shell 变量 1.1 定义变量 定义变量时,变量名不加美元符号($),如: your_name="runoob.com" 注意,变量名和等号之间不能有空格,这可能和你熟悉的所有编程语言都不一样。同时,变量名的命名须遵循如下规则: 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头。 中间不能有空格,可以使用下划线(_)。 不能使用标点符号。 不能使用bash里的关键字(可用hel...

weixin_30446613的博客 159

Shell脚本变量与字符串操作实战:从基础语法到自动化运维应用

在Linux系统管理与自动化运维领域,Shell脚本是连接用户与操作系统的核心工具,其本质是通过命令行解释器执行一系列指令的文本文件。理解其工作原理,关键在于掌握变量与字符串处理这两大基石:变量作为脚本的“记忆单元”,用于存储和传递数据;字符串则是与系统交互、处理文本信息的主要载体。从技术价值看,熟练运用变量扩展、字符串截取与替换等操作,能极大提升脚本的健壮性与灵活性,避免因变量未定义或空格处理不当导致的常见错误。这些技能在日志解析、批量文件处理、配置生成等实际应用场景中不可或缺,是构建高效自动化工作流的基

weixin_34194087的博客 374

【shell】用 grep 查找包含字符串的文件|grep 过滤|取匹配行的前后n行

目标:本文提供一些关于如何搜索出指定目录或整个文件系统中那些包含指定单词或字符串的文件。 难度:容易 约定: #- 需要使用 root 权限来执行指定命令,可以直接使用 root 用户来执行也可以使用sudo命令 $- 可以使用普通用户来执行指定命令 案例 非递归搜索包含指定字符串的文件 第一个例子让我们来搜索/etc/目录下所有包含stretch字符串的文件,但不去搜索其中的子目录: # grep -s stretch /etc/* /etc/os-release:PRET......

我的笔记本 3万+
上一篇: Bash字符串处理(与Java对照) - 18.格式化字符串
下一篇: Bash字符串处理(与Java对照) - 20.查找子串的位置
codingstandards
博客等级 码龄16年 12粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值