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
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Back
Top