I want an array containing the numbers from 1 to twice the number of lines in a text file. In this example, the file somefile.dat has four lines. I tried:
~$ echo {1..$(( `cat somefile.dat | wc -l`*2 ))}
{1..8}
which is not what i wanted. However, what goes on inside the parenthesis has clearly been interpreted as integers. Why then, is the total result a string? And how do I convert it to an int so that I get the numbers 1 to 8 as output?
wc -l < fileto get the number directly. So can you doval=$(wc -l < file).cat somefile.dat | wc -l | perl -nle'for(1..$_*2){print;}'cat somefile.dat somefile.dat | wc -lfor((i=1; i<=$(wc -l <somefile.dat)*2; i++))loop