Results 1 to 9 of 9

Thread: Paste not behaving

  1. #1

    Default Paste not behaving

    I'm writing a script to compile a few different text files together all into one. Whenever I run the script I get errors, but whenever I run the commands by hand in a shell they work fine. The script is running under bash, and my login shell is bash. The commands are exactly the same, down to the last character. The script even works just fine on a different computer running the same OS. Both computers are using 11.2. I'm running the script as root, and root has explicit write access to the directories I'm using. The command I'm using is
    Code:
    paste -d" " file1 file2 file3 file4 > outputFile
    Its not a complicated command by any means. Basically the command in the script leaves me with an empty outputFile, but if I run it in a shell it works just fine.

    Can anyone think of a reason why this is happening? I'm sure its something simple thats going to make me feel pretty dumb for asking, but as it is right now I'm stuck.

    Thanks!

  2. #2

    Default Re: Paste not behaving

    Oh, and let me know if I need to post more information. I think I got everything but I'm not sure.

  3. #3

    Default Re: Paste not behaving

    If it helps I think it has to do with the stdout redirection not working right.

  4. #4
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Paste not behaving

    On 2011-07-12 01:36, blank888 wrote:
    >
    > If it helps I think it has to do with the stdout redirection not working
    > right.


    We know that it works in the shell, and that it doesn't work - where? You
    did not say, or I did not see. How exactly do you run that command that it
    doesn't work?

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.4 x86_64 "Celadon" at Telcontar)

  5. #5

    Default Re: Paste not behaving

    .... nevermind. I figured it out.

  6. #6
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Paste not behaving

    On 2011-07-12 02:36, blank888 wrote:
    >
    > ... nevermind. I figured it out.


    But do tell us! :-)

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.4 x86_64 "Celadon" at Telcontar)

  7. #7

    Default Re: Paste not behaving

    Oh, ok.
    Apparently the computer I was using was having problems referencing the same file twice on one line. So,
    Code:
    cat file1 | grep -v "Something I want to remove" > file1
    was returning me an empty file, but if I ran
    Code:
    cat file1 | grep -v "Something I want to remove" > file2
    rm file1
    mv file2 file1
    That would give me the same result. So it wasn't actually paste's fault. I just couldn't figure it out because I wrote the script on one machine, and it worked using the first bit of code I wrote. But when I moved it to the other machine it needed to use the second bit of code. I blamed paste because
    Code:
    cat file1 | grep -v "Something I want to remove"
    would actually print to the screen what I was trying to save, so I thought the file was getting created correctly. And, if I ran it one the command line, file1 would have what it was supposed to have in it, and paste would perform like I thought it should.

    Meh, just a frustrating little quirk I ran into while in a hurry.

  8. #8

    Default Re: Paste not behaving

    And of course, I could probably have done
    Code:
    grep -v "Something..." file1 > file1
    but far be it from me to do things the easy way.

  9. #9
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Paste not behaving

    On 2011-07-12 19:06, blank888 wrote:
    >
    > And of course, I could probably have done
    > Code:
    > --------------------
    > grep -v "Something..." file1 > file1
    > --------------------
    > but far be it from me to do things the easy way.


    Reading and writing to the same file can be a problem, in any case. :-)

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.4 x86_64 "Celadon" at Telcontar)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •