Set priority on variables in Bash [closed] - bash

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've few variables (the number of variables is dynamic) in csv format as below:-
var1,var2,var3...
I need to prioritize the variables in below manner
priority,variable
1,var1
2,var2
3,var3
......
and then compare the priority of variables using [IF Statement]
So how do I add priority/weight to each of the variables ?

While reading the lines of your file, use IFS and read -a to read the values into an array. Then, it's simple enough to iterate over the array and assign a priority based on the index.
echo "priority,variable"
while IFS=, read -a vars; do
for idx in "${!vars[#]}"; do
echo "$((idx+1)),${vars[idx]}"
done
done << END
a,b,c,d,e,f
END
priority,variable
1,a
2,b
3,c
4,d
5,e
6,f

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.

replace strings with shell variables in text file [closed]

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

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/

Trying to access array within a hash in ruby [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 7 years ago.
Improve this question
I am trying to parse a hash in ruby. I have an array an array of 'entries'. I want to take each entity and get array of runs within it (I want to store the runs in a different variable as seen below). My problem is that runs always turns out nil. Below is my code:
entries = test_plan['entries']
entries.each do |ent|
puts "in entries"
puts ent
runs = ent['runs]']
runs.each do |run|
and what an 'entries' hash looks like.
{"id"=>"7", "suite_id"=>729, "name"=>"Regression", "runs"=>[{"id"=>2588, "suite_id"=>729}]}
There is a simple typo. Change
runs = ent['runs]']
to
runs = ent['runs']

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.

Resources