CAT giving unexpected results
Have: a character matrix such as ...
Code:
abcde Code:
NewRow='NEWROW' This code ... Code:
echo; echo; echo "Add a row to the top of a matrix." Code:
Add a row to the top of a matrix. Now, a variation on the theme..... Have: the same matrix and the same character string. This code (which appears to be the inverse of that shown above) ... Code:
echo "Add a row to the bottom of a matrix." Code:
Add a row to the bottom of a matrix. Note 1) There are other ways to "tack on" a row to the top or bottom of a matrix, such as sed. I'm not looking for alternate solutions, but only an explanation for why cat failed. Note 2) Please don't chide me for a "useless" cat. That's not the point of the question. Daniel B. Martin |
Its late so have not thought this all the way through, however, the issue is not cat but rather your use of re-directions and which order they are being processed in.
I'll have another look in the morning in case no one else elaborates or you don't find the solution using my information :) |
Quote:
Code:
cat < file1 < file2 |
And, to get the result you want, with minimal modification to your logic, use
Code:
echo; echo; echo "Add a row to the top of a matrix." |
Uh… What's wrong with:
Code:
printf '%s\n' "$NewRow" | cat - "$InFile" |
Quote:
Repeating from the original post: Quote:
|
Quote:
Repeating from the original post: Quote:
|
Indeed, as ntubski explained, the problem is the double redirection of the standard input from the pipe and from the here string. The reason is that the last one supersedes the preceding one. In this case the cat command doesn't receive input from the pipe anymore, but only from the here string.
|
Quote:
Quote:
Code:
# stdin ("NEWROW") then $InFile |
Quote:
Thank you also to everyone who contributed to this thread. SOLVED Daniel B. Martin |
Quote:
Misplaced or missing quotes have caused many a stumble. Daniel B. Martin |
All times are GMT -5. The time now is 03:21 PM. |