I have text files that result from various processing steps, so depending on the order of the steps the order columns and length each line changes from one file to the next.
so file1 would be:
moo 100.35 blah 9 85 0.0038
moo 93.8 bluu 10 85 0.0042
and file2 would be:
125.2 129.3 moo 0.23
123.5 125.3 moo 0.23
and I would like to change it to:
1_horatio 100.35 blah 9 85 0.0038
2_horatio 93.8 bluu 10 85 0.0042
and
125.2 129.3 1_clarence 0.23
123.5 125.3 2_clarence 0.23
where the the number on the new name for moo is incremented for each row. The name is an input variable.
here's what I've been trying so far:
newnam=$1
awk -v nnam=$newnam 'BEGIN{ count=1 } {imgn=count"_"nam; print imgn,$2,$3,$4 count++ }' $2 > $3
which I then need to change to:
newnam=$1
awk -v nam=$newnam 'BEGIN{ count=1 } {imgn=count"_"nam; print $1,$2,imgn,$4 count++ }' $2 > $3
I'd like to be able to put the column number as a variable, and not have to worry about how many columns there are. There can be up to 50 column, with up to a million rows.
Is there a way to do this in awk? Or bash with awk?