Oke so i want to make a script that automaticaly install some apps adds some lines to some files replace some lines from files

For the install i use apt-get -y install packagename
For adding line im using :

sudo sh -c 'echo "#Name" >> /etc/apt/sources.list'
sudo sh -c 'echo "deb http://addres onceric main" >> /etc/apt/sources.list'

Is this correct?? is there a better way???From what i read about this problem it adds at the bottom of the file correct??

I want to remove somthing from a file eg. #deb http:// i want to remove the # from this line how can i do this?

I want to replace some lines in some files eg. program.desktop;program2.desktop
how can i do this???
i tried

wfind="program1.desktop;program2.desktop;program.2.desktop;programxxxx.desktop;"
wreplace="program2.desktop;otherprogram.desktop;moretext;ect;"
sed 's/$wfind/$wreplace/g' ~/file.txt > ~/file.txt

But i got an error that command s is not recognize or somthing like that??

Recommended Answers

All 2 Replies

sed 's/$wfind/$wreplace/g' ~/file.txt > ~/file.txt

A couple gotchas. You are reading and modifying file.txt at the same time. "No bueno!"
Quotes is always something to be mindful due to the shell.

sed "s/$wfind/$wreplace/g" ~/file.txt > tmp.file && mv tmp.file ~/file.txt

want to remove somthing from a file eg. #deb http:// i want to remove the # from this line how can i do this?

Choose!

Remove every first instance of # in every line in file.db

sed 's/#//' file.db

Remove # out any line that starts with it, followed by the characters deb

sed 's/^#deb/deb/' file.db

Remove # out the beginning of line 3

sed '3 s/^#//' file.db

Thnx for the info
But now when im using with "" i get this error:
sed: -e expression #1, char 57: unknown option to `s'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.