1,105,546 Community Members

Automation for Linux

Member Avatar
blackarchan
Newbie Poster
4 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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??

Member Avatar
Aia
Nearly a Posting Maven
2,307 posts since Dec 2006
Reputation Points: 1,977 [?]
Q&As Helped to Solve: 236 [?]
Skill Endorsements: 20 [?]
 
0
 

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
Member Avatar
blackarchan
Newbie Poster
4 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article