Input from STDIN, a regular file, or a compressed file - Aix

This is a discussion on Input from STDIN, a regular file, or a compressed file - Aix ; Probably not the correct venue, but I'll try here anyway since its the correct platform. I have a ksh script that invokes awk with "inline" commands. The input may come from STDIN or from a regular file, or from a ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Input from STDIN, a regular file, or a compressed file

  1. Input from STDIN, a regular file, or a compressed file

    Probably not the correct venue, but I'll try here anyway since its the
    correct platform.

    I have a ksh script that invokes awk with "inline" commands.

    The input may come from STDIN or from a regular file, or from a
    compressed file.

    Handling the choice betwee STDIN and a regular file is easy
    (if its STDIN, then I don't give awk a filename)...
    ....however, I don't know how to handle it if it is a compressed
    file...
    ....I need to run zcat $filename and pipe its output to awk...

    If the choices were "regular file" or "compressed file"... I could
    detect the filetype
    with basename and either "cat" or "zcat" the file and pipe the output
    to awk...

    In a perfect work I would do something like this pseudo-code:

    if input is STDIN
    CAT=
    PIPE=
    FILE=
    else
    PIPE="|"
    FILE=$1
    if input is regular_file
    CAT=cat
    else
    CAT=zcat
    fi
    fi

    $CAT $PIPE awk 'awk-commands.....'

    But, that of course doesn't work.

    Suggestions Please...

    Thanks,
    -tony

  2. Re: Input from STDIN, a regular file, or a compressed file

    Quick thought:
    multicat :
    ( zcat .profile 2>/dev/null || cat .profile ) | awk ....

  3. Re: Input from STDIN, a regular file, or a compressed file

    On Jun 25, 1:44*pm, Hajo Ehlers wrote:
    > Quick thought:
    > multicat :
    > ( zcat .profile 2>/dev/null || cat .profile ) | awk ....


    Thanks for the response Hajo.

    That works will work for files... but what if there isn't a file...
    ...that the input is just STDIN and no file is specified...???

    -tony


  4. Re: Input from STDIN, a regular file, or a compressed file

    bennett.tony@con-way.com wrote:
    > Probably not the correct venue, but I'll try here anyway since its the
    > correct platform.
    >
    > I have a ksh script that invokes awk with "inline" commands.
    >
    > The input may come from STDIN or from a regular file, or from a
    > compressed file.
    >
    > Handling the choice betwee STDIN and a regular file is easy
    > (if its STDIN, then I don't give awk a filename)...
    > ...however, I don't know how to handle it if it is a compressed
    > file...
    > ...I need to run zcat $filename and pipe its output to awk...
    >
    > If the choices were "regular file" or "compressed file"... I could
    > detect the filetype
    > with basename and either "cat" or "zcat" the file and pipe the output
    > to awk...
    >
    > In a perfect work I would do something like this pseudo-code:
    >
    > if input is STDIN
    > CAT=
    > PIPE=
    > FILE=
    > else
    > PIPE="|"
    > FILE=$1
    > if input is regular_file
    > CAT=cat
    > else
    > CAT=zcat
    > fi
    > fi
    >
    > $CAT $PIPE awk 'awk-commands.....'
    >
    > But, that of course doesn't work.
    >
    > Suggestions Please...
    >
    > Thanks,
    > -tony


    Untested ...

    if input is STDIN
    FILE = '-'
    else
    FILE = $1
    fi

    if $FILE is compressed_file
    CAT = zcat
    else
    CAT = cat
    fi

    $CAT $FILE | awk 'awk-commands.....'

  5. Re: Input from STDIN, a regular file, or a compressed file

    On Jun 25, 3:34*pm, "J. J. Farrell" wrote:
    > bennett.t...@con-way.com wrote:
    > > Probably not the correct venue, but I'll try here anyway since its the
    > > correct platform.

    >
    > > I have a ksh script that invokes awk with "inline" commands.

    >
    > > The input may come from STDIN or from a regular file, or from a
    > > compressed file.

    >
    > > Handling the choice betwee STDIN and a regular file is easy
    > > (if its STDIN, then I don't give awk a filename)...
    > > ...however, I don't know how to handle it if it is a compressed
    > > file...
    > > ...I need to run zcat $filename and pipe its output to awk...

    >
    > > If the choices were "regular file" or "compressed file"... I could
    > > detect the filetype
    > > with basename and either "cat" or "zcat" the file and pipe the output
    > > to awk...

    >
    > > In a perfect work I would do something like this pseudo-code:

    >
    > > * * if input is STDIN
    > > * * * * *CAT=
    > > * * * * *PIPE=
    > > * * * * *FILE=
    > > * * else
    > > * * * * PIPE="|"
    > > * * * * FILE=$1
    > > * * * * if input is regular_file
    > > * * * * * * CAT=cat
    > > * * * * else
    > > * * * * * *CAT=zcat
    > > * * * * fi
    > > * * fi

    >
    > > * * $CAT $PIPE awk 'awk-commands.....'

    >
    > > But, that of course doesn't work.

    >
    > > Suggestions Please...

    >
    > > Thanks,
    > > -tony

    >
    > Untested ...
    >
    > * * *if input is STDIN
    > * * * * *FILE = '-'
    > * * *else
    > * * * * *FILE = $1
    > * * *fi
    >
    > * * *if $FILE is compressed_file
    > * * * * *CAT = zcat
    > * * *else
    > * * * * *CAT = cat
    > * * *fi
    >
    > * * *$CAT $FILE | awk 'awk-commands.....'- Hide quoted text -
    >
    > - Show quoted text -


    Great...!!!

    That's just the thing I wanted...

    Didn't know that "cat" could take a dash as an argument (like awk &
    tar & ... does)...

    Thanks,
    -tony

  6. Re: Input from STDIN, a regular file, or a compressed file

    On Jun 25, 11:14 pm, bennett.t...@con-way.com wrote:
    > On Jun 25, 1:44 pm, Hajo Ehlers wrote:
    >
    > > Quick thought:
    > > multicat :

    > ( zcat .profile 2>/dev/null || cat .profile ) | awk ....
    >
    > That works will work for files... but what if there isn't a file...
    > ...that the input is just STDIN and no file is specified...???


    2nd edition and supports also compressed data on STDIN ( -f option
    from zcat )

    Data from STDIN ( No valid $1 is allowed )
    ... | ( file=$1; file=${file:--}; zcat $file -f ) | awk ...

    Data from File
    $ set MyFile ; ( file=$1; file=${file:--}; zcat $file -f ) | awk ...

    hth
    Hajo

  7. Re: Input from STDIN, a regular file, or a compressed file

    On Jun 25, 5:56*pm, Hajo Ehlers wrote:
    > On Jun 25, 11:14 pm, bennett.t...@con-way.com wrote:> On Jun 25, 1:44 pm,Hajo Ehlers wrote:
    >
    > > > Quick thought:
    > > > multicat :

    >
    > *> ( zcat .profile 2>/dev/null || cat .profile ) | awk ....
    >
    >
    >
    > > That works will work for files... but what if there isn't a file...
    > > ...that the input is just STDIN and no file is specified...???

    >
    > 2nd edition and supports also compressed data on STDIN ( -f option
    > from zcat )
    >
    > Data from STDIN ( No valid $1 is allowed )
    > *... | ( file=$1; file=${file:--}; zcat $file -f ) | awk ...
    >
    > Data from File
    > $ set MyFile ; *( file=$1; file=${file:--}; zcat $file -f ) | awk ....
    >
    > hth
    > Hajo


    I'm not familiar with "zcat $file -f" ...
    The man page on our AIX 5.3 system does not show a "-f" argument for
    zcat.
    ( i.e. zcat as a part of the "bos.rte.archive" LPP)

    Or is this for the GZIP version of "zcat"... which supports a '-f'
    argument...???
    (i.e. part of the rpm.rte LPP )

    Thanks,
    -tony

  8. Re: Input from STDIN, a regular file, or a compressed file

    ....
    > I'm not familiar with "zcat $file -f" ...
    > The man page on our AIX 5.3 system does not show a "-f" argument for
    > zcat.
    > ( i.e. zcat as a part of the "bos.rte.archive" LPP)


    I was not even aware that AIX has a zcat command. I used the Toolbox
    provided one.

    regards
    Hajo

+ Reply to Thread