Page 1 of 1

[SOLVED] Script to write in .conf/text file.

Posted: Fri 12 Oct 2012, 16:49
by Jejy69
Hi !

Could someone help me create a script please ?

I would like, to integrate the text in a conf file, from a script with different options.
I know this is not well explained ...

I have a config file in / etc / xdg / lxsession / autostart.conf
Content =

Code: Select all

@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash
Using a script, is it possible to add characters in the file, in a precise location?
For example, by running the script, once configured, I want the conf targeted file looks like this :

Code: Select all

@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash
@hello world
Of course, if you have a base, I could then adapt.
It's because, I do not know programming, but I can understand the script. :?

Thanks, if you have questions. Since mine is not really precise... :P I don't know how to explain it.

Cheers !

Posted: Fri 12 Oct 2012, 17:08
by L18L
is it possible to add characters in the file, in a precise location?

Easiest cases first

if you want just append
@hello world
to your file /etc/xdg/lxsession/autostart.conf (no spaces)
then

Code: Select all

echo '@hello world' >> /etc/xdg/lxsession/autostart.conf
will do this :)

or if hello world is the content of par example file1
then

Code: Select all

cat file1 >> /etc/xdg/lxsession/autostart.conf
will do it

Inside, not at end?
use stream editor sed

Code: Select all

sed --help
and/or

Code: Select all

man sed

Posted: Fri 12 Oct 2012, 18:39
by Jejy69
Thank you L18L, :)

I tried with the 'echo' command, it helps me a lot!
Now, if does not bother you, I need again a few tips please :) .

I have this.

Code: Select all

@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash
I'd get it like this:

Code: Select all

@xfce4-panel
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash
I tried with :

Code: Select all

sed -n --line-length=1 -i[/etc/xdg/lxsession/LXDE/autostart]  -e=@xfce4-panel
But doesn't work 8)

It's to replace lxpanel with xfce4-panel, I'm sure I'm wrong in the line, but I do not know where exactly the script does not work.
My syntax is bad, I probably put the commands in the wrong places ...

Script to write in .conf file.

Posted: Fri 12 Oct 2012, 18:58
by L18L
replace
@lxpanel --profile LXDE
by
@xfce4-panel
in file /etc/xdg/lxsession/LXDE/autostart

Code: Select all

sed -i 's/@lxpanel --profile LXDE/@xfce4-panel/' /etc/xdg/lxsession/LXDE/autostart
You might use variables?

Code: Select all

BEFORE='@lxpanel --profile'
AFTER='@xfce4-panel'
sed -i "s/${BEFORE}/${AFTER}/" /etc/xdg/lxsession/LXDE/autostart
Note the double quotes because there are variables inside

Posted: Fri 12 Oct 2012, 19:04
by Jejy69
Yeah ! So Cool, it's perfect !
Thanks you ! :) Exactly what I wanted!

Very fast and efficient, thank you :D