I am trying to get the line contents of file (./answer/answerOnly.txt) to separate files.
Given -> answerOnly.txt:
Ans1
Ans2
Ans3
Ans4
expected output -> files to be created
~/Desktop/miniPro$ ls distributedAnswers/
1.txt
2.txt
3.txt
4.txt
and 1.txt contains:
~/Desktop/miniPro$ cat distributedAnswers/1.txt
Ans1
I have tried ->
for (( i=0;i<count;i++ ))
do
echo -n `awk 'NR==$i' answer/answerOnly.txt &> ./distributedAnswers/$i.txt`
done
output : Empty files are getting created
observation : "awk 'NR==$i'" will only accept numbers. Need a way in which 'NR== ?' accepts variable value.
Thanks and your help is appreciated.