This is a discussion on Appending text files within the Shell scripting forums, part of the Development/Scripting category; I am making my server script big and better but once again i have run into trouble with what i ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
I am making my server script big and better but once again i have run into trouble with what i thought would be the simplest parts of the script.
I want delete one line from a text file and replace it with new. ie delete password"*" from text file and add new password"$" from what i have read the command > deletes all and adds new and >> just adds new line to rest . using google i have seems some thing on sed and awk so i assume i need to use one of them by maybe making a new file then appending then rename back to old but not quite sure how Have tried this sed -e 's/rcon_password "*"/rcon_password "foo"/g' server.cfg > server1.cfg but the out is this rcon_password "foo"origanpass" so the wild card is not getting rid of old pass any help would be great Thanks |
| Sponsored Links | ||
|
|
|
|||
|
I think you want to do find and replace then use replace command:
Code:
replace "OLDTEXT" "NEWTEXT" <INPUT-FILE >OUTPUT-FILE http://www.cyberciti.biz/nixcraft/vi...ng-in-many.php |
|
|||
|
tried that but i get
-bash: replace: command not found I checked out you link and the peal looked good so i tried that and it works same as sed The problem i am having it that i dont no the password with out opening the text file ie.. somewhere in the text file is the line password"foo" so i need to replace password "*" with password "newpass" but the wild card does not seem to work it keeps old pass and adds new one as well. password "foo""newpass" thanks for any help |
|
||||
|
Can you post your sample text/data file, highlighting password entry?
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |
|
|||
|
what it is i am helping a friend run a counterstrike source dedicated servers
He ne not very comfortable using ssh so thought even though i am new to linux myself i would write so scripts to make the job easy the first on my last post mean't he could turn on any servers just be answering a few questions this script will hopefully change to rcon password for each server Code:
// server name hostname "mtservers" rcon_password "foo" // Server password sv_password "edmatch" // server cvars log 0 mp_friendlyfire 1 mp_footsteps 1 mp_autoteambalance 0 mp_autokick 0 mp_flashlight 0 Code:
sed -e 's/rcon_password "*"/rcon_password "bar"/g' server.cfg > server1.cfg Code:
// server name hostname "mtservers" rcon_password "bar"foo" // Server password sv_password "edmatch" // server cvars log 0 mp_friendlyfire 1 mp_footsteps 1 mp_autoteambalance 0 mp_autokick 0 mp_flashlight 0 Code:
perl -p -i -e 's/rcon_password "*"/rcon_password "bar"/g' server.cfg Code:
// server name hostname "mtservers" rcon_password "bar"foo" // Server password sv_password "edmatch" // server cvars log 0 mp_friendlyfire 1 mp_footsteps 1 mp_autoteambalance 0 mp_autokick 0 mp_flashlight 0 From what ive read "" '' `` can cause u hasle may be that where i am going wrong peal works best as i don t need to make new file and it works fine if i type the old pass but that defeats the object of the script. Anyway thanks for any help |
|
|||
|
Thought of work around for old pass but still stuck as now i can t use $ in my code he what ive got so far.
Code:
#dispaly old rcon pass echo -n "The old " cat server.cfg |grep rcon_pass* echo echo #set oldpass and new pass vars echo -n "Please enter old pass : " read oldpass echo echo echo -n "Please enter new pass : " read newpass #set pass #perl -p -i -e 's/$oldpass/$newpass/g' server.cfg sed '/rcon_password/s/$oldpass/$newpass/g' server.cfg > server1.cfg But either would be fine thanks |
|
|||
|
Quote:
|
|
|||
|
Quote:
|
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To find and replace in text file | nashtech | Shell scripting | 3 | 07-31-2008 07:46 PM |
| need to convert text files into mysql database | zafar466 | Databases servers | 2 | 07-12-2008 01:31 PM |
| text output to mysql | chebbab | Shell scripting | 4 | 11-26-2007 08:29 PM |
| rearranging columns in a text file | sureshbup | Shell scripting | 2 | 12-06-2006 10:43 AM |
| Replacing text in a file using awk | postyrus | Shell scripting | 4 | 05-02-2005 04:31 PM |