replace strings with shell variables in text file [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm writing a shell script in which I've created some variables.
RELEASE="something"
COMMONS="something else"
I've got a file file.txt in which there are some occurrences of $RELEASE and $COMMONS. I want to replace these strings with the corresponding shell variable. I've tried to run (and a lot of other variations):
sed "s|\$RELEASE|${RELEASE}|g" file.txt > result.txt
It replaces "$RELEASE" with "${RELEASE}." Have you any idea how to replace by the value of $RELEASE?

Try this :
sed 's|$RELEASE|'"$RELEASE"'|g' file.txt > result.txt

Related

Meaning of 2 in's in shell script for loop? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What does the 2nd "in" do? I can't seem to find this kind of example anywhere other than this one right here.
for a in in /home/davidwright/attachments/*/*.tar
do
echo "extracting $x"
tar -xvf $x
done
Looks like a typo. It means the loop iterates with the string "in" as the first value assigned to a, then proceeds to iterate over the results of the glob. The shell's just not that picky, and every item after the first in is a thing to iterate over in the for loop. Unless there is a file named in that is known to exist, tar will complain when it tries to unpack the non-existent in file.

Delete word from phrase bash [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I would like to delete the word blob from phrase $CHANGEDSITE. but my code isn't working. Any suggestions?
#!/bin/bash
OLD=$1 ex. https://github.com/retep-mathwizard/imitate/blob/master/bjqx
NEW=raw.githubusercontent.com
CHANGEDSITE="${OLD/github.com/$NEW}"
REMOVEDBLOB="${CHANGESITE/blob/}"
echo $REMOVEDBLOB
Forgot a D in my variable, So CHANGESITE was nothing , hence the output being nothing
You can use sed
OLD=https://github.com/retep-mathwizard/imitate/blob/master/bjqx
echo $OLD | sed 's/github.com/raw\.githubusercontent\.com/g' | sed 's/blob\///g'
The First sed change the url and the second remove the word blob/

Check if Hash is included in output [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to check if a specific element is included in an output. I run:
results.include? {"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100}
but I get an error:
Syntax error, unexpected =>, expecting '}'
What did I do wrong?
The problem is that the curly brackets in this case are interpreted as start of a block. Just put () around:
results.include?({"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100})

Bash case statement to create file [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hello i am creating a simple case statement menu to implement an address book and i am having trouble.
the menu work fine but i am having trouble understanding why the file is not created through this command.
this is just primary testing to see if a file is created but is is giving me an operand error so i tried adding .txt to the end and it gave no feedback.
1) echo "Please enter a name for your addressbook"
read addName
touch $addname
break;;
read addName vs. $addname The names are not the same (uppercase n vs. lowercase n)
You could try this.
echo "Please enter a name for your addressbook"
read addName
touch $addName.txt
break;;
for a text file.

Reading all files inside a folder with bash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
The problem is to read all files inside a folder and apply certain functions specified in the bash script over each file. Somewhat like calling map() in an object in JavaScript, but in this case with bash.
you just need to loop over the files. Assume your pwd is that folder:
for file in *.txt; do
do your stuff here with "$file" ...
done

Resources