Skip to main content

All Questions

Tagged with
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 ...
grepit's user avatar
  • 213
3 votes
1 answer
3k views

Shell command executed differently in a terminal and script

The following sequence of commands ch=`echo "b_d" | sed 's/_/\\\\\\\\_/'` echo $ch when executed in a terminal or via source give an output b\\_d When ran as a scipt sh script.sh where the ...
Viesturs's user avatar
  • 943
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\*\*|...
bfoddy's user avatar
  • 185
4 votes
5 answers
1k views

sed using double quotes with \!b leads to unknown command on back slash

I currently have a sed command that I want to act on the following type of text: user: ensure: 'present' uid: '666' gid: '100' home: '/home/example' comment: ''...
TopHat's user avatar
  • 346
1 vote
1 answer
662 views

A variable with quotes as a sed command produces an error

I have this script: num='[0-9]' sedcmd='-e "s/${num}/as df/g"' echo 123 | sed -r $sedcmd The last line produces this: sed: -e expression #1, char 1: unknown command: `"' What did I miss?
Lumify's user avatar
  • 441
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 ...
Jim's user avatar
  • 10.2k
35 votes
4 answers
72k views

find and replace with sed with slash in find and replace string

I want to change in file /var/www with /home/lokesh/www with sed command sed -i 's///var//www///home//lokesh//www/g' lks.php but this give error sed: couldn't open file ww///home//lokesh//www/g: No ...
LOKESH's user avatar
  • 505
1 vote
1 answer
2k views

The differences between sed #, %, / and |

I'm trying to replace a string in database. I found the possible solutions below. Using # or % works to me, but not for / and |. Can anyone explain why the first two works and what the differences are ...
Stickers's user avatar
  • 123
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\...
HashWizard's user avatar
1 vote
2 answers
2k views

Use sed command with variables

I have tried every possible solution available on the Stack Overflow and its related websites but did not find any solution. I spent a reasonable amount of time on this issue and am finally posting ...
kskp's user avatar
  • 177
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 ...
roymaztang's user avatar
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 ...
jixiang's user avatar
  • 121
0 votes
1 answer
343 views

\1 in sed command not working under xonsh

I don't understand what I'm missing here: $ echo 'testing' | sed -E 's/([a-z]*)ing/\1ing/g' ing I would expect the output to be testing again, since \1 should be test? That input seems to have been ...
OJFord's user avatar
  • 1,995
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 ...
phonycollectibles's user avatar
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 ...
boolean.is.null's user avatar

15 30 50 per page