2
votes
3answers
93 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 ...
2
votes
2answers
67 views

Replace a backslash with sed

I've been trying to create a script that would replace every occurence of C:\ in two different types of file by /root. My arborescence looks like : - Batch - Place of the script - Conf - Appli1 ...
0
votes
1answer
40 views

Quote escaping struggle with grep and sed

I'm writing a bash script to extract data from html tags and I found this command in another thread : grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE, ...
1
vote
1answer
56 views

Handling sed variables with paths in them?

I have an applescript for doing certain things, like search and replace. set lol to quoted form of POSIX path of (choose file with prompt "VälJ Fil") That chooses a file then im doing this set ...
3
votes
5answers
322 views

How to use a shell variable inside sed's s command? [duplicate]

we know that we can get the value of a variable using $ sign: x=3 echo $x 3 Is there other ways that we can use to get the value without using $ sign. I'm asking this because $ sign is a special ...
2
votes
2answers
219 views

Replace value within single quotes in a line that contains certain word using sed command

I have a line as below in a html file, shahar.push(['remoteUrl', 'staging.zazzercode.com']); Depending upon environment, I want to replace the remoteUrl value with sed command. eg, ...
2
votes
1answer
72 views

Change a specific line using sed

I need to change a line in a Java file called DbConnection.java using the sed command. The line is: connection = DriverManager.getConnection("jdbc:mysql://**localhost**/**bajaj**","**root**", ...
2
votes
1answer
76 views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: ...
0
votes
1answer
208 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 ...
0
votes
1answer
103 views

Commands inside bash not being interpreted?

I'm trying to execute a command inside a bash script, $(pwd) is not being interpreted at all, and not even using eval. This do not work: cat apache-vhost.conf | sed 's/{path}/$(pwd)/g' Neither ...
1
vote
2answers
102 views

Different behavior of sed with respect to an array and a string in the presence of backslashes

Let the file foo.txt contain foo\\ bar baz xx Why does the following correctly change "foo\\ bar" to "someotherstuff" in foo.txt? sed -i 's/foo\\\\ bar/someotherstuff/gI' foo.txt while this ...
1
vote
2answers
189 views

Escaping blackslash in sed

I am trying to write a sed command to replace a line in a file. The sed replace required the current working directory, which starts making the command a bit messy because of the characters that need ...
1
vote
2answers
205 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
5
votes
1answer
263 views

Variable in sed

I have a file that contains filenames with absolute path. In the middle of that path, is a variable directory, whenever I hard code the variable part, it works fine, but when I replace it with the ...
5
votes
2answers
3k views

Single command taking two strings to extract string between them, like 'tr' (without expressions)

Saw here a way to use sed to get text between two other strings in a line, like: sed 's/.*starting_text\(.*\)ending_text.*/\1/' but I'd like a simple command (like tr, but for string extraction) ...
4
votes
2answers
270 views

Why do I need to escape regex characters in sed to be interpreted as regex characters?

It seems e.g. cat sed_data.txt | sed 's/\b[0-9]\{3\}\b/NUMBER/g' that I must escape characters to form a regular expression. In this case I had to escape braces in order to be interpreted as a number ...
0
votes
2answers
317 views

sed with auto escape character [duplicate]

CommentAppend() { # Comment line and append line below commented line local comment="$1" # search this line and comment it local append="$2" # Append this line below commented ...
3
votes
2answers
1k views

How to run a remote sed command through ssh if the data includes double quotes (“”)?

I'm trying to run through a list of servers and run the next command: itaig@itaig-lt:~$ ssh root@$srvname "sed -i 's/VNCSERVERARGS[6]="-geometry 1920x1080"/VNCSERVERARGS[6]="-geometry 1152x864"/g' ...
2
votes
3answers
1k views

Using a reference to a bash string variable in sed

I'm a relative Linux novice. Suppose that I have a text file a.txt that contains the following text: A B C Now, if I want to change the text on line 2 (which contains B), I can use the following ...
2
votes
2answers
3k views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
3
votes
6answers
9k views

Using sed to find and replace complex string (preferrably with regex)

I have a file with the following contents: <username><![CDATA[name]]></username> <password><![CDATA[password]]></password> ...
2
votes
3answers
2k views

sed - how to replace a single quote?

This works fine: sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb against a source of @driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click ...
3
votes
2answers
620 views

Colorizing tail output with sed

How would I go about colorizing the output of tail with sed? echo "`tput setaf 1`foo`tput op`" works as expected echo "foo" | sed -e 's/(foo)/`tput setaf 1`\0`tput op`/g' however, does not. What am ...
3
votes
4answers
386 views

Piping paths with different types of quotes for slash substitution

I would like to use sed to convert a path with backslashes to the same path with forward slashes: E.g. I would like to pipe \\path\to\file\ and obtain /path/to/file None of the following commands ...
1
vote
4answers
2k views

Appending a string containing escape character with sed

Currently I use: sed -i -e "5a\\ ${text}" $filename to append something to a certain line, where the variable text contains a string such as "\epsilon". When using echo -E $text the string is ...
24
votes
3answers
48k views

What characters do I need to escape when using sed in a sh script?

Take the following script: #!/bin/sh sed 's/(127\.0\.1\.1)\s/\1/' [some file] If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't ...
2
votes
2answers
2k views

Bash color output fails

Is it sed or echo problem? What I'm doing wrong? $> cat ~/bin/color_test.sh #!/bin/bash ColorOff='\e[0m' # Text Reset BWhite='\e[1;37m' # Bold White string="test TEST test" echo -e ...