Hi all,
I need to get a part of string which follows a pattern 'addr='
For example:
a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype
nfs(rw,addr=192.168.1.17)"
b)test="/dev/root on / typr nfs
(rw,v2,rsize=1024,wsize=1024,hard,udp,nolock,addr= 192.168.1.93)"
I need to get the ipaddress from the above two strings a and b which
follows 'addr='. I tried to use cut, but it accepts only single charter
as delimiter. If I give delimiter as 'addr=' for cut command it gives
me a error.
So please help me.
A bunch of thanks in advance.
Regards,
P.R.Hariram 3 1898
Hari wrote: Hi all,
I need to get a part of string which follows a pattern 'addr='
For example:
a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype nfs(rw,addr=192.168.1.17)" b)test="/dev/root on / typr nfs (rw,v2,rsize=1024,wsize=1024,hard,udp,nolock,addr= 192.168.1.93)"
I need to get the ipaddress from the above two strings a and b which follows 'addr='. I tried to use cut, but it accepts only single charter
as delimiter. If I give delimiter as 'addr=' for cut command it gives me a error.
Regular Expressions are probably the easiest way to do this. Example:
import re
str = """a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype
nfs(rw,addr=192.168.1.17)"
b)test="/dev/root on / typr nfs
(rw,v2,rsize=1024,wsize=1024,hard,udp,nolock,addr= 192.168.1.93)"""
m = re.search("addr=(\d+\.\d+\.\d+\.\d+)", str)
print m.group(1)
-> Prints: 192.168.1.17
Read the Python manual on Regular Expressions (module re) or google for
Python regular expression tutorials if your search is more complex than
this (or if you want to know what's going on). If you want a good
in-depth text on the subject, I'd recommend J. Friedls "Mastering
Regular Expressions."
Have fun.
This is the third problem today which I propose to solve with my stream
editor SE. If the group thinks it could be useful I would submit it the
moment I'm done with the doc, which is in the final stage.
Frederic se = SE.SE ('<EAT> ~addr=[0-9.]+~==(10) | addr\== ') string = """(a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype nfs(rw,addr=192.168.1.17)" b)test="/dev/root on / typr nfs (rw,v2,rsize=1024,wsize=1024,hard,udp,nolock,addr= 192.168.1.93)")""") print se (string)
192.168.1.17
192.168.1.93
----- Original Message -----
From: "Hari" <p.*********@gmail.com>
Newsgroups: comp.lang.python
To: <py*********@python.org>
Sent: Monday, May 08, 2006 12:18 PM
Subject: How to get a part of string which follows a particular pattern
usingshell script
Hi all,
I need to get a part of string which follows a pattern 'addr='
For example:
a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype nfs(rw,addr=192.168.1.17)" b)test="/dev/root on / typr nfs (rw,v2,rsize=1024,wsize=1024,hard,udp,nolock,addr= 192.168.1.93)"
I need to get the ipaddress from the above two strings a and b which follows 'addr='. I tried to use cut, but it accepts only single charter
as delimiter. If I give delimiter as 'addr=' for cut command it gives me a error.
So please help me.
A bunch of thanks in advance.
Regards, P.R.Hariram
-- http://mail.python.org/mailman/listinfo/python-list
Anthra Norell wrote: This is the third problem today which I propose to solve with my stream editor SE. If the group thinks it could be useful I would submit it the moment I'm done with the doc, which is in the final stage.
You keep saying that and getting no response, so I'll take a stab at telling
you why. I take it that when you say 'propose it to the group' and 'submit
it for distribution', you mean include it in the standard library.
My impression (and fervent hope) is that nobody's gonna throw a new,
unfamiliar module straight into the standard library. Put it up somewhere
like the cheese shop and let people kick the tires for a few months/years.
Then if it solves a real need, works well, is sufficiently general, and
isn't handled better by another module, it might be eligible for
consideration for inclusion in the standard library. New modules aren't
just thrown in there willy-nilly.
--
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kali K E |
last post by:
Hi,
I wanted to grep a file for a pattern. The pattern is a dynamic one
stored in the string "rec". I tried to do it as follows:
cmd = "grep -c rec filelist2 > grepdata"
os.system(cmd)
But...
|
by: John F Dutcher |
last post by:
I use code like the following to retrieve fields from a form:
recd =
recd.append(string.ljust(form.getfirst("lname",' '),15))
recd.append(string.ljust(form.getfirst("fname",' '),15))
etc.,...
|
by: David M. Wilson |
last post by:
Hello fellow users!
I've been using Python in a couple of different environments for a few
years now. I have quite often found that I have needed to deal with
filenames which may contain...
|
by: Fred Ma |
last post by:
Hello,
This is not a troll posting, and I've refrained from
asking because I've seen similar threads get all
nitter-nattery. But I really want to make a decision
on how best to invest my time....
|
by: zoro |
last post by:
Hi,
I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party
string handling library that includes some very useful string
functions, in particular I'm interested in BEFORE (return...
|
by: Ed Jay |
last post by:
<disclaimer>js newbie</disclaimer>
My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I...
|
by: Mokita |
last post by:
Hello,
I am working with Taverna to build a workflow. Taverna has a beanshell where I can program in java. I am having some problems in writing a script. I want to extract information from a...
|
by: nithinpes |
last post by:
I tried the following regular expression in script to extract lines not begining with capital letters and not ending with numbers.
if ($str =~/^.+$/) ## similarly /^.+\D$/
{
######...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |