Need help getting multiple substrings from one line using find | grep | sed
My find | grep is this:
Code:
find ../xml | xargs grep -s '<parameter name="ldapPassword">' ../xml/file.xml:<parameter name="ldapPassword">Password</parameter> The result I need is this: file = file.xml password = Password This is what I was using to get the password: Code:
find ../xml | xargs grep -s '<parameter name="ldapPassword">' | sed -e 's/.*ldapPassword">//' -e 's/<\/parameter.*//' |
assuming you have only one password entry in a file you can have a grep -r <key> ../xml | sed 'commands' to collect the information. and command will look like:
s/:.*ldapPassword">/\npassword = /; s!</ldapPass.*$!\n!; s/^/file = /; first will drop everything between : and ldapPassword"> and will insert password = , second will drop the end of the line and third will insert filename = But I have not tested, just wrote it, I have no source files to check |
Assuming this is in a bash script and being assigned to variable(s), the first thing is obvious, you would need to assign to an array if only wanting to do a single pass.
The following would assume knowledge of where the items are: Code:
find ../xml | awk -F"[/:<>]+" '/<parameter name="ldapPassword">/{print $3,$5}' |
All times are GMT -5. The time now is 12:24 PM. |