English 中文(简体)
讲卫生运动的定期表述
原标题:Regular expression in BASH

我希望有人能够回答我的迅速问题,因为我是nut子!

我最近开始在我的贾瓦方案编制中学习定期的表述,但对于如何找到某些特征以便在讲卫生运动中正确开展工作,却感到困惑不解。 例如,根据我的看法,以下法典没有发挥作用。

echo 2222 | grep  2{2} 

我期待它回来:

22

我已尝试过改动,包括:

echo 2222 | grep  2{2} 
echo 2222 | grep -P  2{2} 
echo 2222 | grep -E  2{2} 

但 我完全没有想法。 我确信,这只是一个简单的参数/yn子,会爱一些帮助! P.S I ve 生产了吨 go,我发现每条参考材料都不是在讲卫生运动中操作的;在如此众多的不同平台和发动机上可以运行=

最佳回答
echo 2222 | grep -E  2{2} 
2222

reg形将相应于线上,如果与线上相匹配,则要么在整个线(2222)上打印,要么无。

该公司将提取一部分产出。 为此,你们想要的是:

echo 2222 | sed  s/.*(2{2}).*/1/ 
22
问题回答

您可以使用:

echo 2222 | grep -o  2{2} 

<>除外,它将两次显示产出,因为它与这一行数相匹配。

页: 1

echo 2222 | grep -E  2{2} 

that ll return 2222 that is to say "it s matching your line"

页: 1

echo 22 33 342 22 | sed   s/2{2}/<match>/g 

例如返回

<match> 33 342 <match>

如果你在扼杀开始时只找两件“2”,就没有必要使用外部工具。

string=2222
case "$string" in
 22*) echo "ok";;
esac




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签