Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 10-23-2004, 02:01 PM   #1
LQ Newbie
Registered: Aug 2004
Posts: 8

Rep: Reputation: 0
insert output of sed into a variable


This is a shell-related question.

I would like to insert the ip address of the current x-server into a variable. If the Xdmcp-server and x-server are not the same computer, it looks like $DISPLAY gives <ip-adress>:<display-id> . for example:

Is it possible to remove the ':0.0' from $DISPLAY (probably with sed) and insert it into a new variable, like $DISPLAYHOST?

I allready searched the web for it, but I can't find any solution.

(I would like to run programs on the x-server while having a display of a different computer)

Thanks in advance
Old 10-23-2004, 03:17 PM   #2
Registered: Aug 2004
Location: Chicago
Distribution: Debian testing/unstable
Posts: 82

Rep: Reputation: 15
You can convert the output of any shell command or pipeline to a string by using backquotes (`).

For example, say you wanted to use some l33t encryption on some data, then send it to a variable for later use.

$ export SECRETDATA=`echo data | rot13`
I'm not exactly clear on why you want to do this particular thingy, but whatever, I'll tell you how you could do it. Use cut, not sed.

$ export $DISPLAYHOST=`echo $DISPLAY | cut -f1 -d:`
This sets $DISPLAYHOST to the first colon-delimited field of $DISPLAY.

Last edited by Sinope; 10-23-2004 at 03:22 PM.
Old 10-23-2004, 04:11 PM   #3
LQ Newbie
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
That worked .

THank you very much!

Greetings Hendrik
Old 11-06-2004, 07:54 PM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680
There are several way to do many things. Such a simple variable substitution could be done in bash.

If you wanted the DISPLAY#.SCREEN part:


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert CRLF's with sed? unSpawn Programming 6 11-22-2006 07:46 AM
insert string with sed greg108 Programming 7 02-18-2005 01:11 PM
insert a symbol with sed tonton Programming 5 08-31-2004 11:33 AM
sed command to insert tab? iluvatar Linux - Software 4 06-29-2004 01:56 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:37 PM.

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