Regular Expression
Hi All,
I struggling to replace special characters from string below is the string example. "\nhostname \n\r" I want to remove \n and \r from the string, as of now unable to do so. Looking forward for reply. Regards Sumit Sahay 7044112109 |
Have you tried tr with option -d?
|
Quote:
I was trying below one, sed -i 's/"\nhostname \n\r"/"hostname"/g' known_host.txt Regards Sumit Sahay |
sed doesn't get to see the newline (\n) - it is stripped before the record is passed to be processed. Hence your regex will never match.
|
Quote:
...But I warn you it's easier with tr. Your choice :) |
Quote:
Could you please navigate me to achieve the output. I want to replace \n and \r from the string. |
I've already give you a way to achieve what you want with sed (if I were you I would read some documentation about pattern space modification, for example https://www.gnu.org/software/sed/man...ine-techniques). You need to associate instructions "N" and "s" (+"p" if you used option "-n").
But as stated above, it's much easier with tr applied to the content of your variable... |
Quote:
|
Quote:
|
if the \n and \n\r are explicit within the text then try this, you'll have to mod it for your own usage.
Code:
someline="\nsometinghere\n\r" http://www.softpanorama.org/Tools/tr.shtml |
Quote:
|
Quote:
Code:
someline="\nhereweAre\n\r" |
Quote:
Code:
someline="\nhereweAre\n\r" @sumitsahay: Does it work for you? |
Quote:
|
All times are GMT -5. The time now is 11:34 PM. |