All Questions
84
questions
2
votes
3
answers
11k
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 ...
19
votes
2
answers
94k
views
Passing a variable to sed [duplicate]
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 looks ...
228
votes
7
answers
723k
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>
<dbname><![CDATA[name]]></...
5
votes
2
answers
20k
views
How to escape a single quote? [duplicate]
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
I ...
5
votes
2
answers
6k
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
4
answers
2k
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 ...
2
votes
4
answers
10k
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 ...
415
votes
4
answers
774k
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 ...
8
votes
2
answers
6k
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 "$...