Copy and Paste to a new document

Hello,

I am quite new to shell scripting so don't know all the tools available. What I'm trying to do is open a file optimal.txt search for objectiveValue and copy the number in quotes next to it.

e.g.
...
solutionName="incumbent"
solutionIndex="-1"
objectiveValue="13246"
solutionTypeValue="3"
...
where 13246 would be the number I would want to extract

Then copy and paste it into an existing file testcases.txt at the end of the file.

I thought of just using vim but not sure how that works with shell scripting, been looking at other posts for copy and paste and was thinking of using the function 'sed' but not so sure on how it works.

Thanks,

Stephan

Try:

awk -F= '/objectiveValue/ { gsub(/"/,"", $NF); print $NF; }' < optimal.txt >testcases.txt

Thanks Dennis,

Well seems to do the trip of copying and pasting it into a new file but it seems to overwrite the previous contents every I run it essentially what I want to do is copy and paste it such that the testcases.txt file looks like this

13246
13600
14101

where 13600 and 14101 are objective values from other files.

Use >>testcases.txt instead of >testcases.txt

Thanks Dennis once again for the fast response!

That is essentially what I want to do.

Lastly, in the textcases.txt file I would like to present the data as follows (there the numbers on the left are the initial inputs, which are know)

0.1 13246
0.05 13600
0.01 14101

Could I just add those numbers as additional string to that line of code you wrote?

Yes. It is possible. However, what is the criteria/condition? Pasting a sample of your output with proper explanation will be helpful.

for j in 0.1 0.05 0.01
do
for i in 0.01 0.02 0.05 0.1
do

cd /vol/bitbucket/sr706
mkdir $i$j
./a.out supply_chain.txt Upper_bound.lp Lower_bound.lp 3 test.csv

cd $i$j
awk -F= '/objectiveValue/ { gsub(/"/,"", $NF); print $NF; }' < solution_upper_mixed_integer.txt >>../testcases2.txt

So this is the code i have atm. What I could like the output to look like would be at the end

Epsillon 0.1 ($j)

0.01($i) 13246 (ObjectiveValue)
0.02 13344
0.05 13830
0.1 14260

Epsillon 0.05
....etc

Not sure how clear I was, hopefully it makes sense