How to combine data from 2 file ? How to print ?

Dear friends,

I am just trying to print data from 2 file,namely file_1.txt and file_1.dat (specific column of ROW 1)

file_1.txt
12           13        14          15        99  AMC   69  36 89
12           13        14          15        99  AMC   69  84 -12
12           13        14          15        99  AMC   69  25  56
12           13        14          15        99  AMC   69  12  25
file_1.dat
12   35
15   35
25   87
15   64 

here I need col1, col3, col5, col6 from file_1.txt

I want to print like this

12 14 99 69 12 35
12 14 99 69 15 35 
12 14 99 69 25 87
12 14 99 69 15 64

I am sorting files like this,

for file in `ls *.txt |sort -t"_" -k2n,2`; do

and it should use in order say

file_1.txt and then file_1.dat

then print

awk '{print $1,$3,$5,$6} file_1.txt  > tmp
paste tmp file_1.dat 

I have about 100 file How do I set order in loop ?

I want like this

file_1.txt file_1.dat > output1
file_2.txt file_2.dat > output2
file_3.txt file_3.dat > output3
file_4.txt file_4.dat > output4

for i in {1..100}
do
awk '{print $1,$3,$5,$6} file_${i}.txt  > tmp_${i} 
paste tmp_${i} file_${i}.dat
rm -f tmp_${i}
done

bash guys are smarter they can give you a better replacement.

I am an ugly old korn guy :smiley:

This won't help

till FNR==NR of file_1.dat I want to print file_1.txt selected column from row 1

if I had few files I would have tried something like this ---> not working properly

i=$(awk 'FNR == 1 {print $1,$3,$5,$6 }' OFS="\t" file_1.txt)

awk '{print '$i',$1,$2}' OFS="\t" file_1.dat

Here my problem is how do I put

for loop

for 2 type of file ? I can I input them in order ?

I don't see a reason for it to not work, may be I am not understanding your problem.
Can you esplaing more precisely what exactly are you looking for ?

I need output of

FNR==1
paste tmp file_1.dat
12 14 99 AMC    12   35
    15   35
    25   87
    15   64

above is result of

 paste tmp filename