0

I have a file like this:

1
2
3

I need to copy data n times with an empty line after each copy. I used these commands

#!/bin/sh
num=$(sed -n '1 p' FILE.txt)
for i in {1..  $num }; do cat distance_k.txt >> distance.txt; done

n is a number taken from another file 'FILE.txt' (FILE.txt have form like this :

90
Abcbaahjfh
...

However, it copied only 4 times. Could you please help me? Thank you so much!

bash shell

Output

1
2
3

1
2
3

1
2
3

1
2
3 

1
2
3

...
Binh Thien
  • 363
  • 2
  • 13

1 Answers1

1

Use another kind of loop:

num=$(sed -n '1 p' FILE.txt)
for (( i=0; i<num; i++ ))
do
    cat distance_k.txt
    printf '\n'
done >distance.txt

If you like, you can use for (( i=1; i<=num; i++ )) instead of for (( i=0; i<num; i++ )). It's the same if not using the value of i.

Wiimm
  • 2,971
  • 1
  • 15
  • 25