This question already has answers here:
Shell script - search and replace text in multiple files using a list of strings
(5 answers)
Difference between single and double quotes in Bash
(7 answers)
When to wrap quotes around a shell variable?
(5 answers)
How do I use shell variables in an awk script?
(7 answers)
Closed 4 months ago.
I tried to find and replace certain strings in text file and the replace text contains "/" and sed commond did not work.
then I tried with awk command and it works fine with terminal with fixed variables.
but when I tried to use it with parameters in the loop it dose not work.
I have attached the code that I have write so far. could you please find me a solution.
this works find in terminal
awk '{sub(/input_image/,"https://www.abcd.com/images/XPDDL_R1_20161007.jpg")}1' format2.svg > format2.html
x=1
for param in ${paramO[#]}
do
awk '{sub(/${param}/,"${paramN[x]}")}1' $output_file > temp.txt
cp -rp temp.txt $output_file
let x=x+1
done
Related
This question already has answers here:
Difference between single and double quotes in Bash
(7 answers)
How to use variables in a command in sed?
(4 answers)
Closed 5 months ago.
when I try to delete particular lines in my file using shellscrpit I use below command, It's not working, So can anyone help me on same.
sed -i '${lineNumber}d' <filename>
This question already has answers here:
Concise and portable "join" on the Unix command-line
(10 answers)
How do I set a variable to the output of a command in Bash?
(15 answers)
Closed 2 years ago.
I am trying to read a text file which contains the following sample values:
Apple
Banana
Carrot
...I will then need write them to a variable as a single line delimited by comma.
var1=Apple,Banana,Carrot
How does one do it using bash script? Thank you in advance.
Using sed:
sed -rn 's/\n/;/g;s/^/var1=/p' file
Consume the file as one line (-z). Substitute every newline for ";" and then replace the start of the line with "var1="
This question already has answers here:
Replace one substring for another string in shell script
(16 answers)
Closed 4 years ago.
I've been trying to wrap my head around this for over an hour now and my searches haven't helped yield the answer.
Trying to set a variable inside a bash script. This variable is taking variable-A and removing variable-B from it.
Prefix="$(echo ${Process} | sed -e 's/${Server}//g')"
So if Process=abcd1wxyz01 and Server=wxyz01, then Prefix should end up being abcd1.
I've tried so many iterations from online searches I honestly can't recall what all I've tried.
Your problem are the quotes, as pointed out in afsal_p's answer.
You could do this with parameter expansion instead:
$ process=abcd1wxyz01
$ server=wxyz01
$ prefix=${process%"$server"}
$ echo "$prefix"
abcd1
The ${word%suffix} expansion removes suffix from the end of word.
please use " instead of ' while using bash variables inside sed:
Prefix="$(echo ${Process} | sed -e "s/${Server}//g")"
echo $Prefix
This question already has answers here:
Use a variable's value in a sed command [duplicate]
(6 answers)
sed substitution with Bash variables
(6 answers)
Closed 4 years ago.
i am just trying to append a line from my bash script:
sed -i '$ a TEXT' "filename"
but when TEXT is a variable it does not work
sed -i '$ a $VARIABLE' "filename"
i have tested endless iterations with ',''," before/after $ and ${}, escape with \ etc., but i always get a literal $VARIABLE in my file
ps. please do not propose to use echo:)
This question already has answers here:
I just assigned a variable, but echo $variable shows something else
(7 answers)
Replace a word with multiple lines using sed?
(11 answers)
Closed 4 years ago.
I've got a command that I run that outputs to stdio that I need to redirect to an existing file, replacing the word replaceme with the two lines output by my command.
The command mycommand outputs like this:
somedata=this
somedata=that
I'm able to get the output into an environment variable:
export TWOLINES=$(mycommand)
When I echo it back out it comes out as a single line
echo $TWOLINES
Returns:
somedata1=this somedata2=that
I need to get this content into my file as two lines
Attempting to do:
sed -e "s,replaceme,${TWOLINES}," -i file
Returns: unterminated 's' command
Thoughts or other tools besides sed that could assist?