Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-06-2008, 03:14 PM
|
#1
|
Member
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Rep:
|
Extract part of a string
I have this string:
umbillingnumber=1112223333,uniqueidentifier=200803251301508111112223333,ou=defaultGroup,ou=Mailboxes ,ou=DC-Mailbox,o=MailServer
I want to extract everything up to the first comma, i.e.
umbillingnumber=1112223333
I can't use cut -f1 -d",". This will be part of a piped series of commands examining a file with several lines, and other lines may have commas in them, but no other lines have umbillingnumber in them.
The file looks like this:
...
dcucpictalternatenumber 4445556666
dcucpictwirelessnumber 5556667777
umbillingnumber=1112223333,uniqueidentifier=200803251301508111112223333,ou=defaultGroup,ou=Mailboxes ,ou=DC-Mailbox,o=MailServer
dcfindmefollowme <fmfmsettings enabled="on"
...
I looked at sed and awk but don't see how to perform this simple extraction.
Thanks in advance...
|
|
|
05-06-2008, 03:19 PM
|
#2
|
LQ Newbie
Registered: Dec 2005
Posts: 19
Rep:
|
How about
IFS='
'
cat file | while read aline
echo $aline | grep umbillingnumber
if [ $? -q 0 ]
then
VAR=echo $aline | cut -f1 -d,
other code
fi
done
|
|
|
05-06-2008, 03:20 PM
|
#3
|
LQ Newbie
Registered: Dec 2005
Posts: 19
Rep:
|
should have been -eq on the test
|
|
|
05-06-2008, 03:31 PM
|
#4
|
Member
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Original Poster
Rep:
|
I don't think that will work. What I have so far is:
mlsmailbox --dump --phone 1112223333 | egrep -e 'dcucpictalternatenumber|dcucpictwirelessnumber|umbillingnumber=|dcfindmefollowme' | cut -f1 -d","
I need a single command that I can use instead of the cut -f1 -d","
|
|
|
05-06-2008, 05:17 PM
|
#5
|
Member
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360
Rep: 
|
Does this work?
Code:
sed 's/\(umbillingnumber=[0-9]*\),.*/\1/'
|
|
|
05-06-2008, 05:30 PM
|
#6
|
Member
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209
Rep:
|
How about :
Code:
cat file.txt | grep -o 'umbillingnumber=[0-9]\+'
Last edited by beadyallen; 05-06-2008 at 05:31 PM.
|
|
|
05-06-2008, 05:42 PM
|
#7
|
Moderator
Registered: May 2001
Posts: 29,417
|
Code:
mlsmailbox --dump --phone 1112223333 | awk -F',' '/^umbi/ {print $1}'
?
|
|
|
05-07-2008, 07:18 AM
|
#8
|
Member
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Original Poster
Rep:
|
Thanks to all who replied. The suggestion by Kenhelm:
sed 's/\(umbillingnumber=[0-9]*\),.*/\1/'
worked perfectly!!
|
|
|
All times are GMT -5. The time now is 01:48 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|