0

I have a file which contains commands similar to:

cat /home/ptay89/test/01.out
cat /home/ptay89/testing/02.out
...

But I only want a few of them executing. For example, if I only want to see the output files ending in 1.out, I can do this:

cat commands | grep 1.out | sh

However, I get the following output for each of the lines in the commands file:

: cannot be loaded - no such file or directoryst/01.out

When I copy and past the commands I want from the file directly, it works fine. Are there better ways of doing this?

1
  • Works for me here. Some weird characters in your file i think. Commented Dec 26, 2012 at 0:28

2 Answers 2

2

You probably have spurious carriage returns in your file (created under Windows?). Use tr instead of cat to remove them:

tr -d '\015' <commands | grep 1.out | sh
Sign up to request clarification or add additional context in comments.

2 Comments

Almost +1, but tr does not take a file name as an argument. I think you mean: tr -d '\015' < commands | ...
@WilliamPursell thank you for spotting this. Edited to fix it.
0

Try doing a

grep -e '^cat.*out' commands | grep 1.out | sh

That should ignore any weird characters and take only the ones you need.

1 Comment

@tripleee +1, although you probably mean “win” instead of looke.