Thanks. But the order should consistent with the file name, let say the second column should be the numbers from the file2, and so the hundredth column should be from the file100. ortherwise, these numbers are not in order and are becoming meaningless.
Are your first column always the same and in same order?
If yes, this might help extract col2 from all your files , but you need to paste col1 from one of your files.
I think it works with the following code, but in very an inefficient way.
/*add the file name to the first row*/
for i in file*; do
printf "%20s" ${i} >> $i.txt;
done
printf "\n" >> ../$i.txt;
/*print the numbers of the second row from each file $i*/
for ((j=1;j<=11;j++)); do
for i in file*; do
Num=$(awk "NR==${j}" ${i} | awk -F= '{print $2}');
printf "%20.7f" "${Num}" >> $i.txt;
done;
printf "\n" >> $i.txt;
done;
yes. the data for all formatted in same order and not missing any rows and any column.
Sorry for my bad English and I didn't read the question.
will it be possible to give an output as below?
Paste all col2 side by side from all files with file-names as headers.
awk '
FNR == 1 {
c += 1
d = FILENAME
sub ( /\/.*/, X, d )
D[c] = d
}
{
A[c,FNR] = $2
m = m < FNR ? FNR : m
}
END {
while ( ++k <= c )
printf "%s\t", D[k]
printf "\n"
while ( ++j <= m )
{
while ( ++i <= c )
{
printf "%s\t", A[i,j]
}
printf "\n"
i = 0
}
}
' * > allcol2
---------- Post updated at 02:26 AM ---------- Previous update was at 02:19 AM ----------
Thanks Corona688! yes, "Paste" also does the trick very effectively. This functional is exactly what I expected at the very beginning, which could paste the column from multiple files into a table sheet. However, I didn't know there is a command like "Paste". Now, everything become simple. Thanks again for your help!