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

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!

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

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

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)

… nevermind. I figured it out.

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

But do tell us! :slight_smile:


Cheers / Saludos,

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

Oh, ok.
Apparently the computer I was using was having problems referencing the same file twice on one line. So,

cat file1 | grep -v "Something I want to remove" > file1

was returning me an empty file, but if I ran

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

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.

And of course, I could probably have done

grep -v "Something..." file1 > file1

but far be it from me to do things the easy way.

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. :slight_smile:


Cheers / Saludos,

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