![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 04:47 AM |
| Replacing a line in a file - HELP!!! | maxmave | Shell Programming and Scripting | 1 | 06-04-2008 08:55 PM |
| Replacing end of line with " in a UNIX file | The Observer | Shell Programming and Scripting | 2 | 05-17-2008 02:20 AM |
| Replacing characters in file with line break | johnemb | Shell Programming and Scripting | 10 | 04-26-2007 04:38 AM |
| replacing first line or lines in a file | Terrible | UNIX for Advanced & Expert Users | 3 | 06-28-2006 05:23 PM |
|
|
Submit Tools | LinkBack | Thread Tools | 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 |
| Forum Sponsor | ||
|
|
|
|||
|
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> |