Register
It is currently Wed Sep 17, 2014 5:31 am

SED - change file, net create new


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Fri May 30, 2014 2:14 am   

Joined: Fri May 30, 2014 2:04 am
Posts: 1
Hi!

I'm not programmer, but with a little googling I created small script which is changing some file remotely. It is searching some pattern and when it finds it, then it add one line after it:
Code:

ssh ${user}@srv.domena -t "sed '/^#-* *$country_big *-*/ a\'$srv /etc/p/a.conf > ~/a_new.conf; cat ~/a_new.conf > /etc/p/a.conf; rm ~/a_new.conf"



I'm moving output from sed to some temp file and them moving it to oryginal. But I don't like it so much - in my opinion it is easy to make some mistake this way and destroy oryginal cfg file. Is it possible to modify with sed oryginal file, not creating temporary files?

I also have problem that after that command I have not sorted a part of file. In example. I have file with this data:

#---pattern1---
x
z
s
#---pattern2--
2
4
6
8

and I need to inser a number 7 after pattern2. My command is doing it like that:

#---wzor1---
x
z
s
#---wzor2--
7
2
4
6
8

but I'd like to have this result:

#---wzor1---
x
z
s
#---wzor2--
2
4
6
7
8

Is it possible to use SED this way? To put line after pattern but with correct order?

Thanks for every help! And sorry for my english - it is not my native language :-)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP