The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing the last data of each line ina file jisha Shell Programming and Scripting 6 08-04-2008 07:47 AM
Replacing a line in a file - HELP!!! maxmave Shell Programming and Scripting 1 06-04-2008 11:55 PM
Replacing end of line with " in a UNIX file The Observer Shell Programming and Scripting 2 05-17-2008 05:20 AM
Replacing characters in file with line break johnemb Shell Programming and Scripting 10 04-26-2007 07:38 AM
replacing first line or lines in a file Terrible UNIX for Advanced & Expert Users 3 06-28-2006 08:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-25-2007
malavm malavm is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 8
replacing a line of unknown charecters in a file

Hi All

I have a requirement where using a script I grep a file for string (KSG/Password in below ) , get the next line which is the password and I need replace the whole line of unknown special charecters (encrypted password) with another line as given below .

As in below i need to get the line , assign it to a variable
STRNG="<value>#!OE/+puLDjXm/Yg4W34vHvV6rdiGx0plE</value>" then replace

$STRNG with "<value>psoft123</value>"

The file i grep contains as below

<value>
</NameValuePair>
<NameValuePairPassword>
<name>KSG/Password</name>
<value>#!OE/+puLDjXm/Yg4W34vLvV6rdiGx0plE</value>
</NameValuePairPassword>
<NameValuePair>
<name>KSG/DB_User</name>
<value>vass</value>
</NameValuePair>

when I use 'sed' as below , I get the error "sed:command garbled"

sed 's/'$STRNG'/'<value>psoft123</value>'/' abc.xml > abc1.xml

+ sed s/ <value>#!OE/+puLDjXm/Yg4W34vHvV6rdiGx0plE</value>/<value>psoft123</value>/ abc.xml
+ 1> abc1.xml
sed: command garbled: s/

Can some one please help me with this

Thanks
Malavm
  #2 (permalink)  
Old 07-25-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
sed '/KSG\/Password/{n;s#<value>.*</value>#<value>psoft123</value>;}' abc.xml
  #3 (permalink)  
Old 07-25-2007
malavm malavm is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 8
Hi

Thanks for the reply but I am still getting the error

bash-2.05$ sed '/KSG\/Password/{n;s#<value>.*</value>#<value>psoft123</value>;}' abc.xml
sed: command garbled: /KSG\/Password/{n;s#<value>.*</value>#<value>psoft123</value>;}
  #4 (permalink)  
Old 07-25-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,512
if you are open to alternative, here's a Python script:
Code:
#!/usr/bin/python
data=open("file").readlines()
data=[i.strip() for i in data]
for num,line in enumerate(data):
    if "KSG/Password" in line:
        data[num+1] = "<value>psoft123</value>"

for i in data:
 print i
output:
Code:
 # ./test.py #or use > to redirect to new file
<value>
</NameValuePair>
<NameValuePairPassword>
<name>KSG/Password</name>
<value>psoft123</value>
</NameValuePairPassword>
<NameValuePair>
<name>KSG/DB_User</name>
<value>vass</value>
</NameValuePair>
  #5 (permalink)  
Old 07-25-2007
malavm malavm is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 8
I don't know python scripting , so I wont be able to complete my whole script ,
thank you for the reply
  #6 (permalink)  
Old 07-25-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by malavm View Post
Hi

Thanks for the reply but I am still getting the error

bash-2.05$ sed '/KSG\/Password/{n;s#<value>.*</value>#<value>psoft123</value>;}' abc.xml
sed: command garbled: /KSG\/Password/{n;s#<value>.*</value>#<value>psoft123</value>;}
sorry - my bad:
Code:
sed '/KSG\/Password/{n;s#<value>.*</value>#<value>psoft123</value>#;}' abc.xml
  #7 (permalink)  
Old 07-26-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,951
Code:
awk '{ if ( match($0, "KSG/Password") ) { getline; print "<value>psoft123<\/value>" } else { print } }' filename
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0