extracting multiple consecutive columns using awk

Hello,
I have a matrix 200*10,000 and I need to extract the columns between 40 and 77. I dont want to write in awk all the columns. eg: awk '{print $40, $41, $42,$43 ... $77}'. I think should exist a better way to do this.

Have a look at - man cut

cut -d " " -f 40-77 <filename>

Hi.

The command cut should be useful. The syntax for selecting columns is compact ... cheers, drl

Thanks, but 'cut' only give the first 40 columns and I want the columms after 40. I am going to check - man cut

Sorry, the outfile only have 10 columns and each column is only "0.0000" still another 29 columns like this before the data starts in the original file.

Can you give an example of the original data file - thanks

Hi, this is the first LINE, I think the problem is with the delimiter -d " ". In the original text file I have four spaces between the numbers (when I copied here shows only one space)

0.00000 0.00000

OK - Using nawk:

nawk ' { REC=""; for ( i = 40; i<=77; i++ ) REC=REC " " $i; print substr(REC,2) } ' <filename>

Thanks, it worked. I am going to check the - man nawk

Hello pmm,

Thanks again for your help. I am wondering what is the meaning of 'REC' in :

nawk ' { REC=""; for ( i = 40; i<=77; i++ ) REC=REC " " $i; print substr(REC,2) } ' <filename>

Cheers

REC is only an internal variable used to build the string RECord.
Any variable name can be used.