WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Adding xvnc to .xsession  (Read 6220 times)

Offline uggla

  • Sr. Member
  • ****
  • Posts: 438
Re: Adding xvnc to .xsession
« Reply #15 on: February 01, 2011, 09:17:48 AM »
Is there a simple way to substitute the first line in a text file? (Googled echo, cat, tail and sed but got only confused).

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: Adding xvnc to .xsession
« Reply #16 on: February 01, 2011, 11:11:15 AM »
Is there a simple way to substitute the first line in a text file? (Googled echo, cat, tail and sed but got only confused).

sed '1s/^/inserted-text\n/' -i /home/tc/.xsession

Offline uggla

  • Sr. Member
  • ****
  • Posts: 438
Re: Adding xvnc to .xsession
« Reply #17 on: February 01, 2011, 03:07:03 PM »
That wasn't quite right. This worked though:
sed -e '1d' -e '2i\newtext' -i /home/tc/.xsession

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: Adding xvnc to .xsession
« Reply #18 on: February 01, 2011, 03:33:46 PM »
My reply was based on the snippet I tested with busybox sed:
tc@box:~$ seq 1 3|sed '1s/^/first\n/'
first
1
2
3
A different sed might give you different results.

Offline uggla

  • Sr. Member
  • ****
  • Posts: 438
Re: Adding xvnc to .xsession
« Reply #19 on: February 01, 2011, 04:14:35 PM »
I got the same result but I wanted to substitute the first line, not add a new one.

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: Adding xvnc to .xsession
« Reply #20 on: February 01, 2011, 04:54:42 PM »
Whilst a "delete first line and insert before the second" approach (as mentioned in reply #17) should work I wonder why you don't just substitute the entire line (via a 's/^.*$/replacemnet text/' expression).

Or along the lines of the formerly shown example:
Code: [Select]
tc@box:~$ seq 1 3 | sed '1s#^.*$#first#'
first
2
3

BTW, a few good links related to SED are mentioned here.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: Adding xvnc to .xsession
« Reply #21 on: February 01, 2011, 06:19:51 PM »
I got the same result but I wanted to substitute the first line, not add a new one.

Sorry, I see that now. I did not read your question clearly.

Offline uggla

  • Sr. Member
  • ****
  • Posts: 438
Re: Adding xvnc to .xsession
« Reply #22 on: February 02, 2011, 03:09:18 AM »
Thanks anyway, you pointed me in the right direction.  ;)