2

I need to create a FileToCreate.txt with many rows, which include numerical data values coming

from File1.txt

FiletoCreate.txt:

ncap2 -Oh -s'TOPOBATHY(v1,v2)=v3.'   --- first row

ncap2 -Oh -s'TOPOBATHY(168,361)=20.' --- scnd row

ncap2 -Oh -s'TOPOBATHY(169,366)=22.' ----third row

ncap2 -Oh -s'TOPOBATHY(Vn1,Vn2)=Vn3.'----last nth row

File1.txt:

v1  v2 v3

168 361 20

169 366 22

.    .   .

Vn1 Vn2  Vn3

I tried so far:

ifile=file.txt

st='ncap2 -Oh -s 'TOPOBATHY('

st1=')='

st2='.''

line_no=$(wc -l < $ifile)

for row in 'seq 1 $line_no'; do


cat $ifile | awk -v st=$st -v st1=$st1 -v st2=$st2 


'{if (NR==$row) print(st $1 "," $2 st1 $3 st2 st3)}' >> $tmpdir/tmp

It is one of my very first scripts and it is very artesanal and does not work. PLease somebody

can guide me ?

Thanks in advance, Nella

1 Answer 1

1

Try to see below script works:

#!/bin/bash

while read val1 val2 val3
do
  echo "ncap2 -Oh -s'TOPOBATHY($val1,$val2)=$val3.'"
done < file1.txt > FiletoCreate.txt

The while loop reads the input file1.txt line by line and stores the 3 values in val1, val2 & val3 (assuming these values are space separated).

During each iteration of while, echo prints the values with your strings around it.

The whole while output is redirected to FiletoCreate.txt.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.