Solved

Using regular expression in vi editor

Posted on 2009-04-06
3
1,379 Views
Last Modified: 2013-12-13
Hi,
I am trying to find all three digit numbers in one of my config files:
I am using the vi editor. In the command mode I tried something like this:
/[0-9]{3}, which came back with 'Pattern not found message'
Also tried /%i[0-9]{3} which  gave me the same response as well.
Just cant figure out how to do it.

Please help.
Thanks in advance
0
Comment
Question by:Axonites
3 Comments
 
LVL 14

Assisted Solution

by:Deepak Kosaraju
Deepak Kosaraju earned 200 total points
Comment Utility
I recommend to refer the following links
http://www.lagmonster.org/docs/vi.html
http://www.geocities.com/volontir/

Use following in your vi for your requirement


/[0-9]\{3\}

Open in new window

0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
you may use

/[0-9][0-9][0-9]

But this will not restrict it to 3 digits only since it will match 3 and more digits unless you have space before or after the numbers
0
 
LVL 7

Accepted Solution

by:
Morne Lategan earned 300 total points
Comment Utility
You have 4 possible situations:

1) start of line, text followed, 3 digits, text, end of line (aaa123bbb)
2) start of line, text, 3 digits, end of line (aaa123)
3) start of line, 3 digits, text, end of line (123bbb)
4) start of line, 3 digits, end of line (123)

Use:
[^0-9]: (not a digit)
\d       : A digit
\{3\}  : repeated 3 times
^        : Start of line
$         : end of line
\|        : OR

To configure each of the 4:

1) [^0-9]\d\{3\}[^0-9] which says not-a-digit, 3 digits, not a digit
2) [^0-9]\d\{3\}$ which says not-a-digit, 3 digits, end of line
3) ^\d\{3\}[^0-9] which says start-of-line, 3 digits, not a digit
4) ^\d\{3\}$ which says start of line, 3 digits, end of line
 
Then put OR (\|) between then to say "if 1, 2, 3 or 4 is true":

/[^0-9]\d\{3\}[^0-9]\|[^0-9]\d\{3\}$\|^\d\{3\}[^0-9]\|^\d\{3\}$
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now