Solved

Using regular expression in vi editor

Posted on 2009-04-06
3
1,390 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
ID: 24082979
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
ID: 24083697
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
ID: 24085163
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Setting up static IP - Ubuntu server 16.04 12 95
AWS Central Authentication 1 87
error while installing php56 in redhat enterprise linux 20 50
Moving from Mcrypt to OpenSSL 18 45
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

856 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