0

I have this script:

#!/bin/bash
echo Id,Name,Amount,TS > lfs.csv

I want to insert values that will match the columns I created (as above in the script) , I want for example to insert: 56,"Danny",579,311413567 I want to be able to insert it using 'FOR' loop which will insert values without stopping but to change the values for each insert

2
  • I will be using external text file which will hold the data or I will invoke random data from the bash script which will be changed in this way: in the iteration it will be: 56,"Danny",579,311413567 the next iteration will be: 57,"Danny_1",580,311413568 and so on and on till: n,"Danny_n",n,n Commented May 17, 2017 at 12:45
  • Could you edit your question to show what you have as input and what you want to output? Now your question is quite vague, and I'm sure you don't mean you actually want to output random values. Commented May 17, 2017 at 16:19

1 Answer 1

1

More detail would be useful what you like to achieve exactly, so I made a infinite for loop which put line into the csv incremented numbers you provide by $i. ( I cannot make comment yet to ask you )

Update: I still using a infinite loop to get a number counting up to the endless, and using a variable (u_id) to count from 1 to 100 then reset it back to 1 if it is reach 100.

#!/bin/bash
echo 'Id,Name,Amount,TS,unique_ID' > lfs.csv

u_id=0

for (( id=1 ; ;id++ ))
do
[[ $u_id == 100 ]] && (( u_id = 1 )) || (( u_id +=1 ))

        echo $id",Danny_"$id","$id","$id","$u_id >> lfs.csv

done

If you like to start Amount and TS from bigger number you can do that by modifing $id to $(( id + 50000 )) like:

echo $id",Danny_"$id","$(( id + 300 ))","$(( id + 50000 ))","$u_id >> lfs.csv
Sign up to request clarification or add additional context in comments.

6 Comments

I want to add another column which will be the primary key I want the loop to iterate from 1 to 100 and when it get to 100 it will start to iterate again from 1 to 100 sorry for changing my question but I just got it from my direct manager how can I do that?
The primary key should be unique? So record should look like this? 1-∞,1-100,Name,Amount,TS If you could provide the text file format from the other data (Name,Amount,TS ) came would be help me to make the loops echo, or how should I handle them?
Id , Name, Amount, TS, unique_ID - Id should be running forever as well as name,amount and TS, unique_id should be running from 1-100 and when it gets to 100 it should repeat again from 1-100...Thanks!
I updated my answer, I hope it will suit your need now.
Yes thank you but just one thing I nerd that all other variables will be running forever except one that will run till it get to 100 when it does it will be 1 again and will be run till 100 again.
|

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.