Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have 32 bit string of 0s. Each bit in the string represents some code, for e.g.
1000000000000000000000000000000 = ABC
0100000000000000000000000000000 = DEF
...
0000000000000000000000000000001 = XYZ
I have file of string bit, is there any way to shell script the output to code
for. e.g
1100000000000000000000000000000 should print ABC|DEF
Thanks for your inputs.
edit1:
#nullPointer : the 3 digit letters are example of human readable representation of the 32 bit representation.
In bash:
codes=("ABC" "DEF" ... "XYZ")
bitstring=1100000000000000000000000000000
outstring=""
for i in {0..31}; do
if [ "${bitstring:i:1}" = 1 ]; then
outstring+="|${codes[i]}"
fi
done
echo "${outstring#|}"
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I want find all substring between '(' and ')' delimiters using shell script
ex: a string (123).....(abc)...(0000).....
123
abc
0000
I want to extract all substring from the string and use grep like this:
grep -o -P "(?<=()(.*?)(?=))"
and how to assign the output values that match the conditions to the variables
x=123
y=abc
...
Thanks
As your question is confusing regarding the language to use, using bash:
echo "a string (123).....(abc)...(0000)..... <br/>" | grep -P "(?<=\()(.*?)(?=\))" -o
The same logic can be used in Python
import re
data = "a string (123).....(abc)...(0000)..... <br/>"
print(re.findall("(?<=\\()(.*?)(?=\\))", data))
Output
123
abc
0000
Explanation
(?<=\() : positive lookbehind for (
(.*?) : match everything in a non-greedy way and capture it.
(?=\)) : positive lookahead for )
strr='a string (123).....(abc)...(0000)..... <br/>'
strr=strr.split('(')
plist=[]
for s in range(1,len(strr)):
plist.append(strr[s].split(')')[0])
print(plist)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I would like to mass update existing delay steps in SoapUI with groovy that have the value 1000 milliseconds.
New value should be:
${=(int)(Math.random()*10000)}
Can anyone help?
The SoapUI project file is an XML file. You can replace values in that file with Groovy like this:
def projectFileA = new File('/path/to/your/soapui-project.xml')
def projectFileB = projectFileA.text.replaceAll('your old string', 'your new string')
projectfileA.text = projectfileB
If you don't have a Groovy IDE setup you can use groovyConsole, or you can try it in SoapUI itself.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How to write this pseudo in python:
Display ‘ opening box’
Display ‘Item 1 of 4… common Item!’
‘Item 2 of 4…rare item!’
‘Item 2 of 4…epic item!’
‘Item 2 of 4…legendary item!’
The items are randomly choosen. When this function is called on in the body, it is meant to generate this list.
Try this below :
import random
items = ['Common Item', 'Rare Item', 'Epic Item', 'Legendary Item']
print("Opening Box\n")
for i in range(1, 5):
print('Item '+str(i)+' of 4 ----', random.choice(items))
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
This is the content of a js file, want to append a value by putting a comma to last value.
Input
TRIVIAL_TIMES: [
'tags',
'users',
'jobs',
'teams'
],
Output:
TRIVIAL_TIMES: [
'tags',
'users',
'jobs',
'teams',
'more'
],
sed -i "{ N;N;N;N; s/TRIVIAL_TIMES:.*/TRIVIAL_TIMES:\n\t'tags',\n\t'users',\n\t'jobs',\n\t'teams',\n\t'more'/}" filename.js
This works fine, if there is no content above the TRIVIAL_TIMES, otherwise gives some inconsistent result by duplicating the value. Please help me out.
Thanks in advance.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have two files , one as a template and other as a input file for next command. I have to update my input file based on the values in template
First file looks like as shown below
TKTSPEC.2.ASSETATTRID=REVISION&
TKTSPEC.2.REFOBJECTID=31&
TKTSPEC.2.TICKETSPECID=410&
TKTSPEC.2.SECTION=&
TKTSPEC.3.ASSETATTRID=NUM&
TKTSPEC.3.REFOBJECTID=31&
TKTSPEC.3.TICKETSPECID=411&
TKTSPEC.3.SECTION=&
TKTSPEC.4.ASSETATTRID=MPNUM&
TKTSPEC.4.REFOBJECTID=31&
TKTSPEC.4.TICKETSPECID=412&
TKTSPEC.4.SECTION=&
My Template file looks like
TKTSPEC.2.ASSETATTRID=REVISION&
TKTSPEC.2.TABLEVALUE=5&
TKTSPEC.3.ASSETATTRID=NUM&
TKTSPEC.3.TABLEVALUE=RDPVS&
TKTSPEC.4.ASSETATTRID=MPNUM&
TKTSPEC.4.TABLEVALUE=NEWPROJECT&
My Desired output is as follows
TKTSPEC.2.ASSETATTRID=REVISION&
TKTSPEC.2.TABLEVALUE=5&
TKTSPEC.2.REFOBJECTID=31&
TKTSPEC.2.TICKETSPECID=410&
TKTSPEC.2.SECTION=&
TKTSPEC.3.ASSETATTRID=NUM&
TKTSPEC.3.TABLEVALUE=RDPVS&
TKTSPEC.3.REFOBJECTID=31&
TKTSPEC.3.TICKETSPECID=411&
TKTSPEC.3.SECTION=&
TKTSPEC.4.ASSETATTRID=MPNUM&
TKTSPEC.4.TABLEVALUE=NEWPROJECT&
TKTSPEC.4.REFOBJECTID=31&
TKTSPEC.4.TICKETSPECID=412&
TKTSPEC.4.SECTION=&
I have to check the ASSETATTRID from my first file and then insert a new line with corresponding value from the second file.Second file has value for every assetattrid.
Can this be acheived using awk or other linux based commands ?
One way:
awk -F. 'NR==FNR{getline x;a[$2$3]=x;next}$2$3 in a{print;print a[$2$3];next}1' templatefile inpfile
this oneliner may work for you:
awk 'NR==FNR{k=$0;getline;a[k]=$0;next}$0 in a{$0=$0"\n"a[$0]}1' templ input