LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 02-26-2008, 03:59 AM   #1
viveksnv
Member
 
Registered: Feb 2008
Posts: 38

Rep: Reputation: 15
sed command help


Hai.

My file has
proxy-connection
connection
server-connection

i try to print only the 2 line
connection

sed -n "connection" filename
but print all the lines
 
Old 02-26-2008, 04:16 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
grep '^connection$' FILE

but, with sed:

sed -n '/^connection$/p' FILE

-- The slashes tell sed it's a regex. ^ and $ anchor the expression at the beginning and end of the line. The 'p' flag prints. The regex is the same in grep but it knows it's a regex and always prints only matching lines by default.

Last edited by slakmagik; 02-26-2008 at 04:17 AM. Reason: added explanations
 
Old 02-26-2008, 04:18 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Presuming no whitespace interference ...
 
Old 02-26-2008, 07:40 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Really good SED tutorial here:
http://www.grymoire.com/Unix/Sed.html

Look at the part about addresses
 
  


Reply



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
SED command sachinh Linux - General 4 06-30-2007 02:40 PM
sed command shyamdey Programming 2 08-29-2006 11:06 PM
sed command help jaredhanks Linux - General 4 08-15-2006 04:19 PM
SED Command racingdynamics Linux - General 4 07-25-2006 02:09 PM
sed command pazvant Linux - Software 2 05-09-2004 12:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:43 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
Open Source Consulting | Domain Registration