From: ezhil on
Hi All,

I have a file with 1000 rows and 68 columns. The header for 68 columns
is in the 2nd file (2nd column in the file). There is no key field to
match 2 files. I know that the order of rows are matched in 2 files,
so, it is transposing 2nd column of 2nd file and paste it in the first
row. Shamefully, I did this with Excel and wondering how I could do
this using AWK or SHELL.

Thanks in advance.

Kind regards,
Ezhil
From: Janis Papanagnou on
ezhil schrieb:
> Hi All,
>
> I have a file with 1000 rows and 68 columns. The header for 68 columns
> is in the 2nd file (2nd column in the file). There is no key field to
> match 2 files. I know that the order of rows are matched in 2 files,
> so, it is transposing 2nd column of 2nd file and paste it in the first
> row. Shamefully, I did this with Excel and wondering how I could do
> this using AWK or SHELL.

Maybe something like... (untested)

awk 'NR==FNR {printf("%s%s",$2,(NR<68?OFS:ORS));next} 1' file2 file1


Janis

>
> Thanks in advance.
>
> Kind regards,
> Ezhil
From: Ed Morton on
On 7/22/2010 6:06 AM, ezhil wrote:
> Hi All,
>
> I have a file with 1000 rows and 68 columns. The header for 68 columns
> is in the 2nd file (2nd column in the file). There is no key field to
> match 2 files. I know that the order of rows are matched in 2 files,
> so, it is transposing 2nd column of 2nd file and paste it in the first
> row. Shamefully, I did this with Excel and wondering how I could do
> this using AWK or SHELL.

It sounds like your question is really just "How do I print the 2nd field of one
file before the contents of another file?". If so, then that'd be (untested):

awk '
NR==FNR { printf "%s%s",sep,$2; sep=OFS; next }
FNR==1 { print "" }
1' file1 file2

Ed.
From: ezhil on
On Jul 22, 3:07 pm, Ed Morton <mortons...(a)gmail.com> wrote:
> On 7/22/2010 6:06 AM, ezhil wrote:
>
> > Hi All,
>
> > I have a file with 1000 rows and 68 columns. The header for 68 columns
> > is in the 2nd file (2nd column in the file).  There is no key field to
> > match 2 files. I know that the order of rows are matched in 2 files,
> > so, it is transposing 2nd column of 2nd file and paste it in the first
> > row. Shamefully, I did this with Excel and wondering how I could do
> > this using AWK or SHELL.
>
> It sounds like your question is really just "How do I print the 2nd field of one
> file before the contents of another file?". If so, then that'd be (untested):
>
> awk '
> NR==FNR { printf "%s%s",sep,$2; sep=OFS; next }
> FNR==1  { print "" }
> 1' file1 file2
>
>         Ed.

Thanks a lot Ed. It's brilliant ..
From: ezhil on
On Jul 22, 12:29 pm, Janis Papanagnou <janis_papanag...(a)hotmail.com>
wrote:
> ezhil schrieb:
>
> > Hi All,
>
> > I have a file with 1000 rows and 68 columns. The header for 68 columns
> > is in the 2nd file (2nd column in the file).  There is no key field to
> > match 2 files. I know that the order of rows are matched in 2 files,
> > so, it is transposing 2nd column of 2nd file and paste it in the first
> > row. Shamefully, I did this with Excel and wondering how I could do
> > this using AWK or SHELL.
>
> Maybe something like... (untested)
>
>    awk 'NR==FNR {printf("%s%s",$2,(NR<68?OFS:ORS));next} 1' file2 file1
>
> Janis
>
>
>
> > Thanks in advance.
>
> > Kind regards,
> > Ezhil

Thanks Janis. It prints the first line (taken from file 2) and then
prints the first rows of the file1 and after prints only one column of
file1.