All Questions
19 questions
3
votes
1
answer
10k
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/\&...
1
vote
1
answer
983
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/*/\\n/...
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 script ...
5
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: ''...
1
vote
1
answer
668
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?
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 ...
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 ...
82
votes
2
answers
274k
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"
...
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....
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\]\$ '
...
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\...
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 ...
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 ...
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 '/${...
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 `. ...