LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-20-2013, 07:19 AM   #1
kankan55
Member
 
Registered: Nov 2012
Posts: 32

Rep: Reputation: Disabled
Question sed delimiter


Hi Guys,

I wonder what is the sed option equivalent to cut delimiter like example below

HOSTNAME=XXX

I want only XXX ,so for cut command I use.

echo "HOSTNAME=XXX" |cut -d "=" -f 2

How can I use sed in this way ?

Thank you.

Last edited by kankan55; 02-20-2013 at 07:22 AM.
 
Old 02-20-2013, 07:22 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
I'm not sure why you'd want sed there, but
Code:
echo 'hostname=xxx'|sed -e s/hostname=//
xxx

HTH
 
1 members found this post helpful.
Old 02-20-2013, 07:42 AM   #3
restaurantebucuresti
LQ Newbie
 
Registered: Feb 2013
Posts: 3

Rep: Reputation: Disabled
Thank you chrism01!
 
Old 02-20-2013, 11:01 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,689

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Code:
echo 'hostname=xxx'|sed 's/[^=]*=//'
This of course relies on there not being a chance there is another equals sign in the hostname.
 
1 members found this post helpful.
Old 02-21-2013, 01:40 AM   #5
kankan55
Member
 
Registered: Nov 2012
Posts: 32

Original Poster
Rep: Reputation: Disabled
Thank you very much gentlemen . The reason is I'm newbie on sed and trying to use it as a powerful stream editor.

Quote:
echo 'hostname=xxx'|sed 's/[^=]*=//'
And could you please explain a bit more on the code above. I know that "s/" is search but I don't get this "[^=]*=" .

Thank you.
 
Old 02-21-2013, 06:19 AM   #6
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Rep: Reputation: Disabled
Hi kankan55

you can understand the general syntax for sed command

sed 's/$unwanted/$wanted/' $file

Here s = substitute
$unwanted is what you dont require or want to replace.
$wanted is what you need insted of unwanted.
$file is your input file or u can have a pipe statement.

Quote:
echo 'hostname=xxx' |sed 's/hostname=//'
 
1 members found this post helpful.
Old 02-21-2013, 09:27 AM   #7
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,689

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
[^=]*= - zero or more (*) lots of not the equal sign ([^=]) followed by a single equal sign (=)
 
1 members found this post helpful.
  


Reply

Tags
cut, sed


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
How use CUT -d 'delimiter' is delimiter is a TAB? frenchn00b Programming 12 11-06-2013 04:17 AM
[SOLVED] AWK / SED - Parsing a CSV file with comma delimiter, and some extra needs. PenguinJr Programming 8 05-24-2011 07:28 PM
sed : how to use delimiter Ashok_mittal Linux - Newbie 2 12-17-2008 07:41 AM
c++ get() delimiter ashirazi Programming 3 08-06-2004 06:26 AM
sed with delimiter, bourne uribo Programming 17 04-23-2003 02:42 AM


All times are GMT -5. The time now is 10:53 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