simple ksh program - Unix

This is a discussion on simple ksh program - Unix ; I am new to ksh programming. I am trying to copy the first line from separate txt files and then put all those lines into a new txt file named user_add.txt. I can't seem to figure this out no matter ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: simple ksh program

  1. simple ksh program

    I am new to ksh programming. I am trying to copy the first line from
    separate txt files and then put all those lines into a new txt file
    named user_add.txt. I can't seem to figure this out no matter where I
    look. Any help would be appreciated.

    Thanks

  2. Re: simple ksh program

    On Dec 3, 8:04 am, Charlie wrote:
    > I am new to ksh programming. I am trying to copy the first line from
    > separate txt files and then put all those lines into a new txt file
    > named user_add.txt. I can't seem to figure this out no matter where I
    > look. Any help would be appreciated.
    >
    > Thanks


    head -1 a.txt b.txt c.txt >user_add.txt

  3. Re: simple ksh program

    On Dec 3, 1:23 pm, fjbl...@yahoo.com wrote:
    > On Dec 3, 8:04 am, Charlie wrote:
    >
    > > I am new to ksh programming. I am trying to copy the first line from
    > > separate txt files and then put all those lines into a new txt file
    > > named user_add.txt. I can't seem to figure this out no matter where I
    > > look. Any help would be appreciated.

    >
    > > Thanks

    >
    > head -1 a.txt b.txt c.txt >user_add.txt


    Thank you very much!

  4. Re: simple ksh program

    fjblurt@yahoo.com wrote:
    > On Dec 3, 8:04 am, Charlie wrote:
    >> I am new to ksh programming. I am trying to copy the first line from
    >> separate txt files and then put all those lines into a new txt file
    >> named user_add.txt. I can't seem to figure this out no matter where I
    >> look. Any help would be appreciated.
    >>
    >> Thanks

    >
    > head -1 a.txt b.txt c.txt >user_add.txt


    Alternatively:

    for file in a.txt b.txt c.txt
    do
    read line < "$file"
    echo "$line"
    done > user_add.txt

    This approach takes advantage of I/O redirection a lot, and it takes
    advantage of the idea that "read" reads a single line of a file, which
    will be the first line of any file that was newly opened.

    - Logan

  5. Re: simple ksh program

    On Dec 4, 12:43 am, Logan Shaw wrote:
    > fjbl...@yahoo.com wrote:
    > > On Dec 3, 8:04 am, Charlie wrote:
    > >> I am new to ksh programming. I am trying to copy the first line from
    > >> separate txt files and then put all those lines into a new txt file
    > >> named user_add.txt. I can't seem to figure this out no matter where I
    > >> look. Any help would be appreciated.

    >
    > >> Thanks

    >
    > > head -1 a.txt b.txt c.txt >user_add.txt

    >
    > Alternatively:
    >
    > for file in a.txt b.txt c.txt
    > do
    > read line < "$file"
    > echo "$line"
    > done > user_add.txt
    >
    > This approach takes advantage of I/O redirection a lot, and it takes
    > advantage of the idea that "read" reads a single line of a file, which
    > will be the first line of any file that was newly opened.
    >
    > - Logan


    Logan,

    This works even better. I had issues with the first example becuase it
    also put the filename into the text file as well. Thank you.

  6. Re: simple ksh program

    On Dec 4, 5:15 am, Charlie wrote:
    > On Dec 4, 12:43 am, Logan Shaw wrote:
    >
    >
    >
    >
    >
    > > fjbl...@yahoo.com wrote:
    > > > On Dec 3, 8:04 am, Charlie wrote:
    > > >> I am new to ksh programming. I am trying to copy the first line from
    > > >> separate txt files and then put all those lines into a new txt file
    > > >> named user_add.txt. I can't seem to figure this out no matter where I
    > > >> look. Any help would be appreciated.

    >
    > > >> Thanks

    >
    > > > head -1 a.txt b.txt c.txt >user_add.txt

    >
    > > Alternatively:

    >
    > > for file in a.txt b.txt c.txt
    > > do
    > > read line < "$file"
    > > echo "$line"
    > > done > user_add.txt

    >
    > > This approach takes advantage of I/O redirection a lot, and it takes
    > > advantage of the idea that "read" reads a single line of a file, which
    > > will be the first line of any file that was newly opened.

    >
    > > - Logan

    >
    > Logan,
    >
    > This works even better. I had issues with the first example becuase it
    > also put the filename into the text file as well. Thank you


    head -q *.txt >result

    The "-q" inhibits the output of the file names
    --
    Fred Kleinschmidt

  7. Re: simple ksh program

    On 2007-12-04, fred.l.kleinschmidt@boeing.com wrote:
    > On Dec 4, 5:15 am, Charlie wrote:
    >> On Dec 4, 12:43 am, Logan Shaw wrote:
    >> > fjbl...@yahoo.com wrote:
    >> > > On Dec 3, 8:04 am, Charlie wrote:
    >> > >> I am new to ksh programming. I am trying to copy the first line from
    >> > >> separate txt files and then put all those lines into a new txt file
    >> > >> named user_add.txt. I can't seem to figure this out no matter where I
    >> > >> look. Any help would be appreciated.

    >>
    >> > >> Thanks

    >>
    >> > > head -1 a.txt b.txt c.txt >user_add.txt

    >>
    >> > Alternatively:

    >>
    >> > for file in a.txt b.txt c.txt
    >> > do
    >> > read line < "$file"
    >> > echo "$line"


    That an fail fro some values of $line. Use printf instead:

    printf "%s\n" "$line"

    >> > done > user_add.txt

    >>
    >> > This approach takes advantage of I/O redirection a lot, and it takes
    >> > advantage of the idea that "read" reads a single line of a file, which
    >> > will be the first line of any file that was newly opened.

    >>
    >> > - Logan

    >>
    >> Logan,
    >>
    >> This works even better. I had issues with the first example becuase it
    >> also put the filename into the text file as well. Thank you

    >
    > head -q *.txt >result
    >
    > The "-q" inhibits the output of the file names


    That is a non-standard option:

    $ head -q *html
    head: illegal option -- q
    usage: head [-n lines | -c bytes] [file ...]

    Try this:

    awk 'FNR == 1' a.txt b.txt c.txt > result


    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  8. Re: simple ksh program

    On 2007-12-04, Chris F.A. Johnson wrote:
    > On 2007-12-04, fred.l.kleinschmidt@boeing.com wrote:
    >> On Dec 4, 5:15 am, Charlie wrote:
    >>> On Dec 4, 12:43 am, Logan Shaw wrote:
    >>> > fjbl...@yahoo.com wrote:
    >>> > > On Dec 3, 8:04 am, Charlie wrote:
    >>> > >> I am new to ksh programming. I am trying to copy the first line from
    >>> > >> separate txt files and then put all those lines into a new txt file
    >>> > >> named user_add.txt. I can't seem to figure this out no matter where I
    >>> > >> look. Any help would be appreciated.
    >>>
    >>> > >> Thanks
    >>>
    >>> > > head -1 a.txt b.txt c.txt >user_add.txt
    >>>
    >>> > Alternatively:
    >>>
    >>> > for file in a.txt b.txt c.txt
    >>> > do
    >>> > read line < "$file"
    >>> > echo "$line"

    >
    > That an fail fro some values of $line. Use printf instead:


    [My typing is getting worse and worse as I grow older!]

    That can fail for some values of $line. Use printf instead:

    > printf "%s\n" "$line"
    >
    >>> > done > user_add.txt
    >>>
    >>> > This approach takes advantage of I/O redirection a lot, and it takes
    >>> > advantage of the idea that "read" reads a single line of a file, which
    >>> > will be the first line of any file that was newly opened.
    >>>
    >>> > - Logan
    >>>
    >>> Logan,
    >>>
    >>> This works even better. I had issues with the first example becuase it
    >>> also put the filename into the text file as well. Thank you

    >>
    >> head -q *.txt >result
    >>
    >> The "-q" inhibits the output of the file names

    >
    > That is a non-standard option:
    >
    > $ head -q *html
    > head: illegal option -- q
    > usage: head [-n lines | -c bytes] [file ...]
    >
    > Try this:
    >
    > awk 'FNR == 1' a.txt b.txt c.txt > result



    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

+ Reply to Thread