VI question on overlay - Unix

This is a discussion on VI question on overlay - Unix ; I am trying to overlay a file in VI. Example: good good good good I have a file that is listed like this and I am trying to overlay: abc def gety The results should look like this abc good ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: VI question on overlay

  1. VI question on overlay

    I am trying to overlay a file in VI. Example:
    good
    good
    good
    good

    I have a file that is listed like this and I am trying to overlay:
    abc
    def
    gety

    The results should look like this
    abc good
    def good
    gety good


  2. Re: VI question on overlay

    rogv24@yahoo.com wrote:
    > I am trying to overlay a file in VI. Example:
    > good
    > good
    > good
    > good
    >
    > I have a file that is listed like this and I am trying to overlay:
    > abc
    > def
    > gety
    >
    > The results should look like this
    > abc good
    > def good
    > gety good
    >


    If all you want is to add an extra column of "good"s to your file here's
    some alternatives:

    $ cat file
    abc
    def
    gety
    $ sed 's/$/\tgood/' file
    abc good
    def good
    gety good
    $ awk 'sub(/$/,"\tgood")' file
    abc good
    def good
    gety good
    $ awk '{printf "%s%20s%s\n",$0,"\t","good"}' file
    abc good
    def good
    gety good
    $ cat file2
    good
    good
    good
    good
    $ paste file file2
    abc good
    def good
    gety good
    good
    $ awk 'NR==FNR{file2[FNR]=$0;next}sub(/$/,"\t"file2[FNR])' file2 file
    abc good
    def good
    gety good

    If none of that helps you solve your problem, then answer these questions:

    1) Why do you want to use vi for that instead of paste, sed, or awk?
    2) Why is the second "good" indented one extra space?
    3) How many of each of tab and/or blank characters are between the two
    columns?

    Regards,

    Ed.

  3. Re: VI question on overlay

    Thank you. I had no idea there was a paste command.

    Ed Morton wrote:
    > rogv24@yahoo.com wrote:
    > > I am trying to overlay a file in VI. Example:
    > > good
    > > good
    > > good
    > > good
    > >
    > > I have a file that is listed like this and I am trying to overlay:
    > > abc
    > > def
    > > gety
    > >
    > > The results should look like this
    > > abc good
    > > def good
    > > gety good
    > >

    >
    > If all you want is to add an extra column of "good"s to your file here's
    > some alternatives:
    >
    > $ cat file
    > abc
    > def
    > gety
    > $ sed 's/$/\tgood/' file
    > abc good
    > def good
    > gety good
    > $ awk 'sub(/$/,"\tgood")' file
    > abc good
    > def good
    > gety good
    > $ awk '{printf "%s%20s%s\n",$0,"\t","good"}' file
    > abc good
    > def good
    > gety good
    > $ cat file2
    > good
    > good
    > good
    > good
    > $ paste file file2
    > abc good
    > def good
    > gety good
    > good
    > $ awk 'NR==FNR{file2[FNR]=$0;next}sub(/$/,"\t"file2[FNR])' file2 file
    > abc good
    > def good
    > gety good
    >
    > If none of that helps you solve your problem, then answer these questions:
    >
    > 1) Why do you want to use vi for that instead of paste, sed, or awk?
    > 2) Why is the second "good" indented one extra space?
    > 3) How many of each of tab and/or blank characters are between the two
    > columns?
    >
    > Regards,
    >
    > Ed.



+ Reply to Thread