Replace multiple line code inside square brackets through sed [closed] - linux

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.

Related

SoapUI change milliseconds value in delay step with groovy [closed]

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.

Function outside look that requires a list to be generated that will randomly select 4 options [closed]

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))

Shell scipt to convert bit string to text value code [closed]

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#|}"

Powershell script to read column 2 data from .xlsx file [closed]

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
I'm trying to write a PowerShell script to get of 2 columns of a .xlsx file. Can anyone help me here.
My .xlsx file looks like this:
ProductName ProductCode
----------------------------------------------------------
Java 7 Update 75 {26374892-xxxx-xxxx-xxxx-123456789012}
Java 8 Update 25 {26374892-xxxx-xxxx-xxxx-902341562789}
I want output which will write only product codes line by line
{26374892-xxxx-xxxx-xxxx-123456789012}
{26374892-xxxx-xxxx-xxxx-902341562789}
You could use the ImportExcel Module by Doug Finke to import the spreadsheet into a PowerShell object to operate on:
Install-Module importexcel
Import-Excel C:\path\to\spreadsheet.xlsx | Select-Object -ExpandProperty ProductCode

Need to replace line from one file based on another file in Linux bash shell [closed]

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

Resources