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
if you are open to alternative, here's a Python script:
#!/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:
# ./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>
Your code is working fine , thanks a lot for the solution.
I am trying to understand the code , I am not able to figure out , can you help me please.
matrixmadhan
when I execute the commond , I am getting the error as below ,
bash-2.05$ awk '{ if ( match($0, "KSG/Password") ) { getline; print "<value>psoft123<\/value>" } else { print } }' abc.xml
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1