![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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>;} |
|
||||
|
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
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> |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|