Skip to main content

All Questions

Tagged with
0 votes
1 answer
233 views

How to escape this bash script's string?

This is my foo.sh: #!/bin/bash sed -i -- 's/<meta http-equiv="Content-Security-Policy" content="default-src * data: blob: 'unsafe-inline' 'unsafe-eval' ws: wss:;">/<meta my custom meta>/...
Edgar's user avatar
  • 1
2 votes
1 answer
257 views

Why do my single quotes vanish on substitution with sed

What is the right command for: sudo sed -i '/, false);/adefine( 'WP_MEMORY_LIMIT', '64M' );' /var/www/html/wp-config.php The result is: define( WP_MEMORY_LIMIT, 64M ); instead of the desired: ...
victor212's user avatar
45 votes
1 answer
52k views

using sed with ampersand (&)

I'm using sed to find and replace patterns within SAS files I have rather than changing them individually. The problem is I am trying to replace macro variables and when I use the ampersand it is not ...
DukeLuke's user avatar
  • 553
1 vote
3 answers
236 views

Unable to use a escape sequences in a variable in a sed command

I'm using sed to highlight a column in the output of a ps command, and it works fine if I hard code the color code. However, the color needs to be dynamic, so I tried moving it to a variable, and ...
Justin's user avatar
  • 495
1 vote
1 answer
764 views

Rewrite a find command that uses sed -i for AIX

I have a script that searches for a string and replaces it via the sed command. If that string contains special characters, the script will escape them (except for the slash because it's my current ...
Rich B. Goodman's user avatar
4 votes
4 answers
18k views

Bash converting path names for sed so they escape [duplicate]

I'm having a problem with a script. It is meant to change a value in a file called %DIR% so that it becomes a path name. The problem is the slashes in the directory name upset sed, so I get weird ...
John Tate's user avatar
  • 1,990
2 votes
5 answers
92 views

Editing a sed statement

I'm writing a script to change on the fly the firefox home page through a text variable: sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "$ddrs"|' /home/max/.mozilla/firefox/*.default/prefs.js ...
Symb932's user avatar
  • 365
2 votes
2 answers
2k views

Insert text in specific lines of a file? with special characters

I know this has been answered several times, but I can't figure out how to use it for my project. I have several php files and want to add a new string between line 11 and 12. this is the string I ...
SchnitzelKopf's user avatar
0 votes
3 answers
6k views

How to correctly use quotes in sed? [duplicate]

For example I want to change "'this text'" "that text" 'other_text' into 'this text' "that text" 'other_text' I tried sed -e 's/^"\'/"/g' but my quoting must be off. Ubuntu.
Michael Durrant's user avatar
81 votes
2 answers
266k views

Slash and backslash in sed [duplicate]

I want to use sed to change a slash into a backslash and a slash, i.e. / -> \/. But it does not work. Here a small example: #!/bin/bash TEST=/etc/hallo echo $TEST echo $TEST | sed "s/hallo/bello/g" ...
devopsfun's user avatar
  • 1,417
0 votes
2 answers
107 views

sed replace ;" content with ';"

I have files that contain ;" and I need it replaced with ';" The following sed command does not work: sed -i "s/;"/';"/g" /root/bashy.sh How can I do this? The solution doesn't have to be sed.
Teddy77's user avatar
  • 3,033
2 votes
1 answer
1k views

How do I properly escape this long su + sed command?

#!/bin/bash wineuser=tom su $wineuser -c "sed -i '$ialias ptgui "wine ~/.wine/drive_c/Program\ Files/PTGui/PTGui.exe\"' /usr/people/$wineuser/config/cshrc.csh" The acutal line inserted to tom's cshrc....
Party Time's user avatar
0 votes
3 answers
4k views

How can I add a line including single quotes to a file with sed [duplicate]

I want to append the following line to a text file with sed: gem 'forum2discourse' I've tried sed -i '$a gem \'forum2discourse\'' Gemfile but this drops me to a > prompt so I think I must be ...
codecowboy's user avatar
  • 3,502
6 votes
1 answer
678 views

Why can't I escape the braces "]" in sed?

Question: Why can't I escape the "]"? $ printf "*#$@~\!&*()[]\n" *#~\!&*()[] $ printf "*#$@~\!&*()[]\n" | sed 's/[*#$@~!&*()\[\]]//g' *#~\!&*() $
LoukiosValentine79's user avatar
1 vote
1 answer
5k views

Using sed to replace a string with special chars with another string with special characters

I'm trying to automate switching out a bash prompt for another in .bashrc Original String: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' ...
daedalus's user avatar

15 30 50 per page