Skip to main content

All Questions

Tagged with
3 votes
1 answer
9k views

Escaping backlash and double quotes inside a sed expression (surrounded by double quotes)

$ echo 'output: " ' | sed "s/\"/\"/" output: " $ echo 'output: " ' | sed "s/\"/\\\"/" output: " $ echo 'output: " ' | sed "s/\&...
pi-star's user avatar
  • 33
1 vote
1 answer
521 views

sed bash script is unexpectedly replacing character with space instead of newline [duplicate]

Using bash command syntax: echo "The*quick*brown*fox"|sed s/*/\\n/g I get the desired output: The quick brown fox However in script: IN_TXT="The*quick*brown*fox" OUT_TXT=$(echo $IN_TXT|sed s/*/\\...
SPB's user avatar
  • 13
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
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
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
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
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
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
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
4 votes
2 answers
2k views

Replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0. So this is the command currently used: sed -i 's/1\...
Tak's user avatar
  • 539
2 votes
3 answers
2k views

sed won't expand my BASH variable in script

I have this script, which will prompt for the relative or absolute path to the file and then swap whitespaces ' ' with '\ ' which works in Linux console. Substitution is done using the first sed ...
71GA's user avatar
  • 1,176
5 votes
2 answers
18k views

Left and right square brackets treated differently by sed/bash

I have a file with the following contents: [root@server list]# cat filenames.txt [AAA','ACMEDEMO2','ACMEDEMO3','ACMEDEMO4','RENTCOGH','TESTENT','DORASINE','LOKAWINK','BBB] [root@qa4app01 list]# I ...
Sreeraj's user avatar
  • 5,092
2 votes
3 answers
8k views

Call sed to replace a string stored in a bash variable

I want to expand a variable in bash with sed or awk. This variable is an array. For example, the script must delete strings contained in array. I tried ARRAY1=( string1 string2 string3 ) sed -i '/${...
elbarna's user avatar
  • 12.8k
10 votes
1 answer
10k views

Escaping multiple backticks in a sed call

I need to perform search and replacement iteratively in several SQL statements: From: CREATE TABLE `Old_Name` ( To: ALTER TABLE `Old_Name` RENAME TO `New_Name` The above query contains backticks `...
Question Overflow's user avatar

15 30 50 per page