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

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Jejy69
Posts: 710
Joined: Thu 20 Jan 2011, 18:10
Location: Perpignan

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

#1 Post 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 !
Last edited by Jejy69 on Fri 12 Oct 2012, 19:10, edited 1 time in total.
I'm Commander Shepard and this is my favorite Linux distrbution on the Citadel.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#2 Post 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

User avatar
Jejy69
Posts: 710
Joined: Thu 20 Jan 2011, 18:10
Location: Perpignan

#3 Post 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 ...
I'm Commander Shepard and this is my favorite Linux distrbution on the Citadel.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Script to write in .conf file.

#4 Post 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
Last edited by L18L on Fri 12 Oct 2012, 19:06, edited 3 times in total.

User avatar
Jejy69
Posts: 710
Joined: Thu 20 Jan 2011, 18:10
Location: Perpignan

#5 Post by Jejy69 »

Yeah ! So Cool, it's perfect !
Thanks you ! :) Exactly what I wanted!

Very fast and efficient, thank you :D
I'm Commander Shepard and this is my favorite Linux distrbution on the Citadel.

Post Reply