Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

split data numbers into two columns in shell script

I have numbers from 1 to 1000 in file ($y).

for i in {1..1000}
do
echo "$i" >> $y
done

I want to split numbers into two column in the file(user enters the filename that indicates "$y").

1    501
.    .
.    .
500  1000 

like this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried ‘split -l500 $y’ and ‘column -t ‘ command but couldnt get result.

>Solution :

What I would do:

printf '%d\t%d\n' {1..100} 
1    2
3    4
5    6
[...]

Then:

printf '%d\t%d\n' {1..100} | while read i; do
        echo "$i" >> "$y"
    done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading