Sed - Replacing "blattnig" with "blattnig/sirest"

  • Thread starter Thread starter Norman
  • Start date Start date
AI Thread Summary
To replace the phrase "blattnig" with "blattnig/sirest" in a file using the sed command, the slash (/) must be escaped because it is used as a separator in the command syntax. This can be done by using a backslash (\) before the slash, resulting in the command: s/blattnig/blattnig\/sirest/. Alternatively, the separator can be changed to a different character, such as a tilde (~), allowing the command to be written as s~blattnig~blattnig/sirest~. The ampersand (&) can also be used to repeat the search pattern, as in s/blattnig/&/sirest/. Understanding these syntax rules is crucial for effective use of sed commands.
Norman
Messages
895
Reaction score
4
I need some help with a sed command.

want to take a file new.f and replace the phrase "blattnig" with "blattnig/sirest" every where in it. Well sed doesn't seem to like the slash. Is there an escape character in sed so it reads the / correctly?
thanks,
Ryan
 
Computer science news on Phys.org
backslash (\) will escape the / like this:

s/blattnig/blattnig\/sirest/

also, & repeats the search pattern like this:

s/blattnig/&\/sirest/

Also, the reason you need to escape the slash is because you used the slash for a separator. Try this:

s~blattnig~&/sirest~

In other words, the first character after the s is the separator.
 
jimmysnyder said:
backslash (\) will escape the / like this:
s/blattnig/blattnig\/sirest/
also, & repeats the search pattern like this:
s/blattnig/&\/sirest/
Also, the reason you need to escape the slash is because you used the slash for a separator.
it didn't like this at all. It still atleast the first one.

Try this:
s~blattnig~&/sirest~
In other words, the first character after the s is the separator.

very good to know! you don't have to use the / as a separator. Thanks a ton for the quick reply.
Cheers,
Ryan
 
This week, I saw a documentary done by the French called Les sacrifiés de l'IA, which was presented by a Canadian show Enquête. If you understand French I recommend it. Very eye-opening. I found a similar documentary in English called The Human Cost of AI: Data workers in the Global South. There is also an interview with Milagros Miceli (appearing in both documentaries) on Youtube: I also found a powerpoint presentation by the economist Uma Rani (appearing in the French documentary), AI...
Back
Top