All Questions
28
questions
1
vote
1
answer
435
views
How to insert ESC control characters in a file in FreeBSD?
I want to enclose Fortran comments with two escape commands (ESC+E and ESC+F).
This implies detecting the comment that begins with ! until end of line, and prefixing it with ESC+E and suffixing it ...
2
votes
1
answer
24k
views
Replacing '\'' with sed
I want to replace '\'' in a text file to another word or character using sed command.
Tried using sed "s/'\''/×/g" but it doesn't work.
Anyone know the solution?
4
votes
2
answers
20k
views
Escaping ' (single quote) in sed replace string [duplicate]
I have a script that I'm using to perform some iptables changes across servers. In the script I have a sed command to find a string and insert iptables rule before that line.
The problem I'm having ...
0
votes
1
answer
74
views
complicated command replace in files using sed [duplicate]
I want to replace the below strings
replace: print 'Status Code: {code}'.format(code=r.status_code)
with: print('Status Code: {code}'.format(code=r.status_code))
Here is the command I ran which ...
2
votes
2
answers
220
views
shell variable test expansion problem
I have this code:
sed \
$( (( $compress == 1 )) && echo -n '-e /^RMTHOST/ s/$/, compress/' ) \
-e "s|\*\*jobname\*\*|$jobname|g" \
-e "s|\*\*hostname\*\*|$hostname|g" \
-e "s|\*\*hostport\*\*|...
0
votes
1
answer
640
views
Do I need to double quote a variable?
I am confused on when we double quote shell variables.
Specifically I am using the following sed replace command:
sed -i.tmp "/$MY_VAR/d" /foo/bar/file.txt
But I am not quoting $MY_VAR. Is this ...
2
votes
2
answers
1k
views
Parallelizing sed gives different output
Trying to parallelize a sed operation however, while the parallel version works, it gives back a wrong output.
The sed operation that I would like to parallelize (works)
sed 's/\s.*$// ; s/\(.*\)/\L\...
3
votes
1
answer
2k
views
How to pass a list of variables into sed in a shell function
I want to append multiple variables to the end of a line that contains a certain string. Here is my function:
function () { sudo sed -i '/^STRING/ s/$/ '$@'/' FILE; }
However I got sed: -e ...
2
votes
2
answers
5k
views
How to escape quotes in shell within both usage of ssh and sudo?
In one word:
question and example could test locally:
sh -c "echo 'how to print single quote here'"
details:
I have a config like this:
upload_server = ('192.168.1.1', 10051)
now I need a shell ...
5
votes
3
answers
7k
views
Problem with passing a variable to sed
I know that when passing a variable to sed, one should use double quote. So when I was using sed to display a line of a file given a line number:
sed '894!d' cloud.cpp
It works, but since I also ...
0
votes
1
answer
982
views
Termination issue with sed
In a sed script, I have the following line, which needs to be updated by sed:
opennic="nameserver 95.85.9.86\nnameserver 185.83.217.248\nnameserver 193.183.98.154\nnameserver 5.9.49.12"
The sed ...
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>/...
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:
...
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.
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.