LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed delimiter (https://www.linuxquestions.org/questions/linux-newbie-8/sed-delimiter-4175450938/)

kankan55 02-20-2013 06:19 AM

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.

chrism01 02-20-2013 06:22 AM

I'm not sure why you'd want sed there, but
Code:

echo 'hostname=xxx'|sed -e s/hostname=//
xxx


HTH

restaurantebucuresti 02-20-2013 06:42 AM

Thank you chrism01!

grail 02-20-2013 10:01 AM

Code:

echo 'hostname=xxx'|sed 's/[^=]*=//'
This of course relies on there not being a chance there is another equals sign in the hostname.

kankan55 02-21-2013 12:40 AM

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.

pradeepdee6 02-21-2013 05:19 AM

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=//'

grail 02-21-2013 08:27 AM

[^=]*= - zero or more (*) lots of not the equal sign ([^=]) followed by a single equal sign (=)


All times are GMT -5. The time now is 11:51 PM.