LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-23-2010, 06:52 AM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 167

Rep: Reputation: 15
Matching double quotes "


Code:
Dhcp Server 190.21.12.50 add scope 190.21.12.0 255.255.255.0 "New York" ""
I am using this to extract the network and mask.

Code:
grep "add scope" file | cut -d" " -f6,7
What would one use to extract the Description between the double quotes?

Thanks & Regards,

Last edited by hattori.hanzo; 11-23-2010 at 06:57 AM.
 
Old 11-23-2010, 06:59 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Code:
grep "add scope" file | cut -d'"' -f2
 
1 members found this post helpful.
Old 11-23-2010, 07:02 AM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,597
Blog Entries: 1

Rep: Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046
awk -F\" '{print $2}' file
or
awk -F\" '{print $2,$4}' file
To match the contents of the second double quotes
 
1 members found this post helpful.
Old 11-23-2010, 07:43 AM   #4
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Thanks for the input but is it possible to accomplish this in one line.

I guess I could run it thru twice then combine the output.

Quote:
grep "add scope" file | cut -d" " --output-delimiter="/" -f6,7
grep "add scope" file | cut -d'"' -f2
Thanks & Regards,
 
Old 11-23-2010, 07:58 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
How about:
Code:
sed -r '/add scope/s@.*scope ([^ ]+) ([^ ]+) "([^"]+)".*@\1/\2 \3@' file
 
1 members found this post helpful.
Old 11-23-2010, 08:06 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Using awk (as previously suggested by sycamorex):
Code:
$ awk -F\" '/add scope/{n = split($1,_," "); printf "%s/%s %s\n", _[6], _[7], $2}' file
190.21.12.0/255.255.255.0 New York
 
Old 11-23-2010, 08:07 AM   #7
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by grail View Post
How about:
Code:
sed -r '/add scope/s@.*scope ([^ ]+) ([^ ]+) "([^"]+)".*@\1/\2 \3@' file
Hi grail! Nice sed one-liner!
 
Old 11-24-2010, 01:49 AM   #8
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Thanks guys. I will need to study both sed and awk solutions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Double Quotes Inside Double Quotes youarefunny Programming 6 06-09-2010 11:21 PM
Problems with quotes and double quotes Andruha Slackware 6 01-02-2010 05:44 PM
While working on Fedora10,unable to print double Quotes dancewithpratik Linux - Newbie 3 02-23-2009 07:26 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 12:41 PM
US Intl Keybd; Double quotes not showing in some apps Heinz Linux - General 6 01-10-2004 04:48 PM


All times are GMT -5. The time now is 09:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration