shell script(Preferably awk or sed) to print selected number of columns from each row

Hi Experts,

The question may look very silly by seeing the title, but please have a look at it clearly.

I have a text file where the first 5 columns in each row were supposed to be attributes of a sample(like sample name, number, status etc) and the next 25 columns are parameters on which I am interested in looking at.

But the problem is for some of the rows in the text file we don't have all the 5 columns(first 5 fields). Then the parameter column will be left offset by 1 or 2 columns etc depending on the number of missing attribute columns.

So I decided to print the last 25 columns starting from the last column so that for each sample I get my required parameters from which I need make some plots.

I need the script preferable using awk, sed and grep.

Many thanks friends..

Reddy,

Can You pls. post sample input and output your expecting .

Try this:

awk '{for(i=0;i<25;i++){printf("%s ", $NF-i)}print ""}' file
nawk '{for(i=NF-25;i<=NF;i++) printf("%s%c", $i, (i<NF)?OFS:ORS)}' myFile

OR in reverse order of fields

nawk '{for(i=0;i<25;i++) printf("%s%c", $(NF-i), (i<24)?OFS:ORS)}' myFile