Help displaying info from 2 files - awk

This is a discussion on Help displaying info from 2 files - awk ; Hi all, I m new to AWK so forgive me if this is pretty simple These are my i/p files: # cat file1 a b c d # cat file2 1 2 3 4 My required output: a 1 b ...

+ Reply to Thread
Results 1 to 10 of 10

Help displaying info from 2 files

  1. Default Help displaying info from 2 files

    Hi all,

    I m new to AWK so forgive me if this is pretty simple


    These are my i/p files:

    # cat file1
    a
    b
    c
    d

    # cat file2
    1
    2
    3
    4

    My required output:

    a 1
    b 2
    c 3
    d 4


    I need to do this with as AWK program.


    Can anyone help???


    Thanks in advance,
    Fazlin


  2. Default Re: Help displaying info from 2 files


    / fazlin :
    > Hi all,
    >
    > I m new to AWK so forgive me if this is pretty simple
    >
    >
    > These are my i/p files:
    >
    > # cat file1
    > a
    > b
    > c
    > d
    >
    > # cat file2
    > 1
    > 2
    > 3
    > 4
    >
    > My required output:
    >
    > a 1
    > b 2
    > c 3
    > d 4
    >
    >
    > I need to do this with as AWK program.
    >
    >
    > Can anyone help???
    >
    >
    > Thanks in advance,
    > Fazlin


    Hi,
    There is a common non-awk solution for this

    paste -d ' ' file1 file2

    If you still want an awk solution, the usual way is (maybe a problem
    for big files)

    awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1 file2

    Vassilis


  3. Default Re: Help displaying info from 2 files

    On Jun 4, 4:02 pm, Vassilis <F.H.Nova...@> wrote:
    > / fazlin :
    >
    >
    >
    >
    >
    > > Hi all,

    >
    > > I m new to AWK so forgive me if this is pretty simple

    >
    > > These are my i/p files:

    >
    > > # cat file1
    > > a
    > > b
    > > c
    > > d

    >
    > > # cat file2
    > > 1
    > > 2
    > > 3
    > > 4

    >
    > > My required output:

    >
    > > a 1
    > > b 2
    > > c 3
    > > d 4

    >
    > > I need to do this with as AWK program.

    >
    > > Can anyone help???

    >
    > > Thanks in advance,
    > > Fazlin

    >
    > Hi,
    > There is a common non-awk solution for this
    >
    > paste -d ' ' file1 file2
    >
    > If you still want an awk solution, the usual way is (maybe a problem
    > for big files)
    >
    > awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1 file2
    >
    > Vassilis- Hide quoted text -
    >
    > - Show quoted text -


    But this awk solution gives me a o/p as below:

    a
    b
    c
    d
    1
    2
    3
    4



  4. Default Re: Help displaying info from 2 files


    / fazlin :
    > On Jun 4, 4:02 pm, Vassilis <F.H.Nova...@> wrote:
    > > / fazlin :
    > >
    > >
    > >
    > >
    > >
    > > > Hi all,

    > >
    > > > I m new to AWK so forgive me if this is pretty simple

    > >
    > > > These are my i/p files:

    > >
    > > > # cat file1
    > > > a
    > > > b
    > > > c
    > > > d

    > >
    > > > # cat file2
    > > > 1
    > > > 2
    > > > 3
    > > > 4

    > >
    > > > My required output:

    > >
    > > > a 1
    > > > b 2
    > > > c 3
    > > > d 4

    > >
    > > > I need to do this with as AWK program.

    > >
    > > > Can anyone help???

    > >
    > > > Thanks in advance,
    > > > Fazlin

    > >
    > > Hi,
    > > There is a common non-awk solution for this
    > >
    > > paste -d ' ' file1 file2
    > >
    > > If you still want an awk solution, the usual way is (maybe a problem
    > > for big files)
    > >
    > > awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1 file2
    > >
    > > Vassilis- Hide quoted text -
    > >
    > > - Show quoted text -

    >
    > But this awk solution gives me a o/p as below:
    >
    > a
    > b
    > c
    > d
    > 1
    > 2
    > 3
    > 4


    Are you sure? Did you try this awk script with given files? I cannot
    think of a way that *this* script produces the output you show. Maybe
    you made a typo? Check again


  5. Default Re: Help displaying info from 2 files

    On Jun 4, 4:56 pm, Vassilis <F.H.Nova...@> wrote:
    > / fazlin :
    >
    >
    >
    >
    >
    > > On Jun 4, 4:02 pm, Vassilis <F.H.Nova...@> wrote:
    > > > / fazlin :

    >
    > > > > Hi all,

    >
    > > > > I m new to AWK so forgive me if this is pretty simple

    >
    > > > > These are my i/p files:

    >
    > > > > # cat file1
    > > > > a
    > > > > b
    > > > > c
    > > > > d

    >
    > > > > # cat file2
    > > > > 1
    > > > > 2
    > > > > 3
    > > > > 4

    >
    > > > > My required output:

    >
    > > > > a 1
    > > > > b 2
    > > > > c 3
    > > > > d 4

    >
    > > > > I need to do this with as AWK program.

    >
    > > > > Can anyone help???

    >
    > > > > Thanks in advance,
    > > > > Fazlin

    >
    > > > Hi,
    > > > There is a common non-awk solution for this

    >
    > > > paste -d ' ' file1 file2

    >
    > > > If you still want an awk solution, the usual way is (maybe a problem
    > > > for big files)

    >
    > > > awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1 file2

    >
    > > > Vassilis- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > But this awk solution gives me a o/p as below:

    >
    > > a
    > > b
    > > c
    > > d
    > > 1
    > > 2
    > > 3
    > > 4

    >
    > Are you sure? Did you try this awk script with given files? I cannot
    > think of a way that *this* script produces the output you show. Maybe
    > you made a typo? Check again- Hide quoted text -
    >
    > - Show quoted text -


    </home/fazlin/awk_prg>
    awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1
    file2
    a
    b
    c
    d
    1
    2
    3
    4
    </home/fazlin/awk_prg>

    This is wat i did and the o/p i got!!

    Thanks,
    F


  6. Default Re: Help displaying info from 2 files


    / fazlin :
    > On Jun 4, 4:56 pm, Vassilis <F.H.Nova...@> wrote:
    > >
    > > Are you sure? Did you try this awk script with given files? I cannot
    > > think of a way that *this* script produces the output you show. Maybe
    > > you made a typo? Check again- Hide quoted text -
    > >
    > > - Show quoted text -

    >
    > </home/fazlin/awk_prg>
    > awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1
    > file2
    > a
    > b
    > c
    > d
    > 1
    > 2
    > 3
    > 4
    > </home/fazlin/awk_prg>
    >
    > This is wat i did and the o/p i got!!
    >
    > Thanks,
    > F



    I see. I tried:

    awk '{ print a[FNR], $1 }' file1 file2

    and got the same results. Seems your awk doesn't understand FNR and
    next.
    Get a new awk, probably gawk. If you're running Solaris try /usr/xpg4/
    bin/awk.


  7. Default Re: Help displaying info from 2 files

    On Jun 4, 5:57 pm, Vassilis <F.H.Nova...@> wrote:
    > / fazlin :
    >
    >
    >
    >
    >
    > > On Jun 4, 4:56 pm, Vassilis <F.H.Nova...@> wrote:

    >
    > > > Are you sure? Did you try this awk script with given files? I cannot
    > > > think of a way that *this* script produces the output you show. Maybe
    > > > you made a typo? Check again- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > </home/fazlin/awk_prg>
    > > awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1
    > > file2
    > > a
    > > b
    > > c
    > > d
    > > 1
    > > 2
    > > 3
    > > 4
    > > </home/fazlin/awk_prg>

    >
    > > This is wat i did and the o/p i got!!

    >
    > > Thanks,
    > > F

    >
    > I see. I tried:
    >
    > awk '{ print a[FNR], $1 }' file1 file2
    >
    > and got the same results. Seems your awk doesn't understand FNR and
    > next.
    > Get a new awk, probably gawk. If you're running Solaris try /usr/xpg4/
    > bin/awk.- Hide quoted text -
    >
    > - Show quoted text -


    Yeah i tried with gawk and it works.

    Thanks a lot,
    F


  8. Default Re: Help displaying info from 2 files


    / fazlin :
    > On Jun 4, 5:57 pm, Vassilis <F.H.Nova...@> wrote:
    > >
    > > I see. I tried:
    > >
    > > awk '{ print a[FNR], $1 }' file1 file2
    > >
    > > and got the same results. Seems your awk doesn't understand FNR and
    > > next.
    > > Get a new awk, probably gawk. If you're running Solaris try /usr/xpg4/
    > > bin/awk.- Hide quoted text -
    > >
    > > - Show quoted text -

    >
    > Yeah i tried with gawk and it works.
    >
    > Thanks a lot,
    > F


    Just out of curiosity, could you post your OS and (non gawk) awk
    version?


  9. Default Re: Help displaying info from 2 files

    Vassilis wrote:
    > / fazlin :
    >
    >>On Jun 4, 4:56 pm, Vassilis <F.H.Nova...@> wrote:
    >>
    >>>Are you sure? Did you try this awk script with given files? I cannot
    >>>think of a way that *this* script produces the output you show. Maybe
    >>>you made a typo? Check again- Hide quoted text -
    >>>
    >>>- Show quoted text -

    >>
    >></home/fazlin/awk_prg>
    >>awk 'NR == FNR { a[FNR] = $1; next } { print a[FNR], $1 }' file1
    >>file2
    >> a
    >> b
    >> c
    >> d
    >> 1
    >> 2
    >> 3
    >> 4
    >></home/fazlin/awk_prg>
    >>
    >>This is wat i did and the o/p i got!!
    >>
    >>Thanks,
    >>F

    >
    >
    >
    > I see. I tried:
    >
    > awk '{ print a[FNR], $1 }' file1 file2
    >
    > and got the same results. Seems your awk doesn't understand FNR and
    > next.


    The only way that output could be produced is if NR is never equal to FNR.

    > Get a new awk, probably gawk. If you're running Solaris try /usr/xpg4/
    > bin/awk.
    >


    Please try these:

    awk --version

    awk { print FILENAME ":" NR ":" FNR ":" $1 }' file1 file2

    and post the output.

    Ed.

  10. Default Re: Help displaying info from 2 files

    On Jun 4, 6:19 pm, Vassilis <F.H.Nova...@> wrote:
    > / fazlin :
    >
    >
    >
    >
    >
    > > On Jun 4, 5:57 pm, Vassilis <F.H.Nova...@> wrote:

    >
    > > > I see. I tried:

    >
    > > > awk '{ print a[FNR], $1 }' file1 file2

    >
    > > > and got the same results. Seems your awk doesn't understand FNR and
    > > > next.
    > > > Get a new awk, probably gawk. If you're running Solaris try /usr/xpg4/
    > > > bin/awk.- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > Yeah i tried with gawk and it works.

    >
    > > Thanks a lot,
    > > F

    >
    > Just out of curiosity, could you post your OS and (non gawk) awk
    > version?- Hide quoted text -
    >
    > - Show quoted text -


    I m using an unix that is used specific for my company and it is an
    very old one.. it doesnt even print version if i give "awk --version"

    Thanks,
    F


+ Reply to Thread

Similar Threads

  1. Custom File Info panels not displaying in CS3
    By Application Development in forum Adobe Photoshop
    Replies: 0
    Last Post: 09-11-2007, 04:09 AM
  2. displaying jpg files from search pages
    By Application Development in forum Sharepoint
    Replies: 4
    Last Post: 06-18-2007, 11:19 AM
  3. AE not displaying large files ( 1 or more gig + )
    By Application Development in forum Adobe After Effects
    Replies: 1
    Last Post: 01-12-2007, 12:15 AM
  4. Detailed ASP.Net info not displaying in browser
    By Application Development in forum XML SOAP
    Replies: 20
    Last Post: 08-30-2006, 06:35 AM
  5. Index Server - 3.0 Only displaying .xls and .doc files?
    By Application Development in forum Inetserver
    Replies: 0
    Last Post: 05-17-2004, 04:59 PM