Quote:
Originally Posted by
liorfe
Thank you Alex for the examples, its exactly what I needed.
I used sed 's/^\(.*PASS=\).*/\1*****/' and it did the job.
Can you explain me what this sed contains?
I glad it's helped.
The explanation of that command:
- 1 - commands are between single quotes (could be between double quots.)
- 2 - s is for substitute; the form is s/<search part>/<replace part./[<option>]
- 3 - in the 'search': the ^ - represent the 'beginning of the string'
----- the \( and \) are the define the part that need to be remembered. To reference the remembered part a consecutive number is used: here it is the first pair; so, it is refered by the \1
----- the back slashes in \(, \), \1 are used to escape the simbol to be not treted by the executing shell as a simbol to be 'expanded' (how it is named in manuals) So, to be not replaced by the shell before 'sed' has received the command
----- the dot after \( is represents an any character. The * after the dot means 'to have a character 0 or more times' (Therefore I do not understand the
BMDancorrection with addition the [^=] - the ^ inside of the [] means 'not'; not sure if '=' get some meaning, but without any special meaning the [^=]* means: 'does not have '=' 0 or more times' that make no sence for me. Also, Ive checked the 'PASS=' and it has been selected (as expected) by the ^.*PASS= ... - so, I am not clear what the note was about)
----- After than in the command is the litteral string "PASS=", followed by '.*', which is the same - any character 0 or more times (and the end of the 'remember' part)
- 4 - In the 'replace' part there is the remembered part and the litteral 5 *. So, even if line with no password string will be found, it will put the '*****' after '=', as it was something.
- 5 - there is no needs for any option after third /
- 6 - any command could be finished by ';' and another command could be given. That how I've process later with 'for .. - loop'.
I hope it explains the construction of the sed command.
You can find more than enough links with sed-explanations (including the man-pages,) by google, for example, but it is not easy to understand, IMHO.
Quote:
Originally Posted by
liorfe
Or maybe give a link to read? I need to make an adaptation of it and I need to know more.
I have the following line in the log :
ORA_CONNECT_STRING=username value/password
The username name is taken from the $USERNAME variable.
How do I write the sed to change the password to *****?
sed 's/^\(.*CONNECT_STRING='"$USERNAME"'/\).*/\1*****/'
Is that correct ?
As you have later said the $USERNAME is not available in time of processing. So, it is better to reffer it as an 'something', than as the exact word, how you have it done here. And it is not needed the .* in beginning, because you exactly know what it should be. So:
's/^\(ORA_CONNECT_STRING=.*\/\).*/\1*****/'
- see the '/' is used in search string, but to prevent the sed from getting it as the search part end, it has to be escaped by the back-slash: \/
(I did not checked it, but it should work.)