Change word
I use the below command to change the string , it works,
sed -e "s/aaa/bbb/" file can advise if now the string is not aaa , it is c:\path , what can i do ? thx |
See grymoire on the slash as a delimiter
Edit 1: you could see it; it's quite interesting, but it doesn't answer your question :( Edit 2: I wanted to give you a link to a page that explains, to help you help yourself, but have not been able to find one that explains clearly and is easy to understand. Your aaa is a very simple "regular expression" meaning, er, aaa. Regular expressions are very powerful ways to describe strings of characters. Example: [hc]at matches "hat" and "cat". Here the [hc] means h or c. But what if you wanted to find exactly [hc]at? Then you can remove the special meaning of [ and ] by "escaping" them with a backslash, like this: \[hc\]at. Now sed will look for exatly "[hc]at". You want to find "c:\path". As a regular expression, c:\path means c:path. The \ has been used to remove any special meaning from p so the \ itself has disappeared! What to do? You didn't want \ to be used that way, you wanted it to stand for itself. That's OK, you know how to remove the special meaning from a character by "escaping" it with a backslash. So give c:\\path to sed and it will look for c:\path. |
Quote:
|
elainelaw,
Just a point of encouragement. Catkin has done a good job at explaining things that would have taken you about 10+ minutes to read from a good tutorial. If I were you, I would give him/her the highest compliment by pressing that blue thumbs-up icon at the lower right corner of the post. That icon is our only currency here, acceptable as payment to any form of indebtedness in our work, something that money can't buy. :) Well done catkin. good luck elaine. |
Thanks malekmustaq :)
Quote:
Best Charles |
Here's a site to interactively learn/test regexes.
http://www.regexbuddy.com/ Note that the regex rules are not(!) identical for every tool that does regexing ... sigh .. ;) The best book is Mastering Regular Expressions, by Jeffrey Friedl; see http://regex.info/ Gets very high marks from Amazon, O'Reilly and me :) . |
thx all suggestion , I will give a icon as you said once I fully solve my problem .
I have one more question , the command is works to run on the shell , but it is not in my application , I try sed -e "s/c:\/bbb/g" , it can replace c" to bbb on my application, but use sed -e "s/c:\\\aaa/bbb/g" is only work on shell but not in my application ( my application enivornment is quite complicate to me , I am not sure how to expliant the details ) But I think the problem is because it can not see c:\\\aaa as a string , I would like to ask if I can add something like a quote "" to it so that it see anything in the quote as a string ? or can anyone provide another method to replace the string ( other than sed -e "s/c:\\\aaa/bbb/g" file > file.new ) that I would try . thx in advance. |
What is the language of your application? If it is calling SED, that implies that it is a shell script.
Please post the exact commands you are using, an example of the input data, and the results you are getting.. Watch out for the backslash: suppose you are in a situation where one "\" means to "escape" the character following. To get a literal "\" in that situation, you need "\\". Thus, "\\\" means literal "\", followed by the escaped value of the next character. So, in your example, "c:\\\a" means literal "c:\", and an escaped "a". The latter has no meaning in a sed command. |
Quote:
thx reply , my command is sed -e "s/c:\\\aaa/bbb/g" if run from my application , it will not do anything ( the exact command is unix silent sed -e "s/c:\\\aaa/bbb/g" ) , if I save this command to a script ( my_script ) , then run this program from my application , it is OK ( the excat command is unix silent my_script ) , can advise what is wrong in my case ? thx |
I don't know excat but the symptoms suggest it is parsing the command in a similar manner to bash before handing it to bash.
|
Quote:
Code:
unix silent sed -e "s/c:\\\aaa/bbb/g" If the above is actual code, then what is it supposed to do? |
Quote:
I wonder why elainelaw hasn't told us which environment is being used to issue the command? Hens teeth and blood out of stones! |
All times are GMT -5. The time now is 02:25 AM. |