0

I have a simple question, but I can't find an answer )

I have following script:

sqsh -S SyBaseServer -U sybuser -P mypass -C 'select top 10000 * from dba.sybtable; -mbcp' | \
awk '{print substr($0, 0, length($0)-1)}' | \
psql -1 postgresql://admin:adminpass@pgserv:5432/pgbase -f sybtopg.sql

How can I add EOF after last string of ouput of awk? I must close STDIN for psql.

Thanks!

PS The reason of fail isn't lack of EOF. It's right pipeline:

sqsh -S SyBaseServer -U sybuser -P mypass -C 'select top 10000 * from dba.wybtable; -mbcp' \
| awk '{print substr($0, 0, length($0)-1)}' | \
/psql  postgresql://admin:adminpass@pgserv:5432/pgbase -c "DELETE FROM testtable; COPY testtable FROM STDIN DELIMITER '|' CSV"
4
  • Possible duplicate of how does ` cat << EOF` work in bash? Commented Nov 5, 2015 at 22:18
  • awk will write EOF when it reads EOF from its input. Commented Nov 5, 2015 at 22:55
  • @t0mm13b How is this related? There's no here-doc in this question. Commented Nov 5, 2015 at 22:56
  • IIUC the reader of a pipe should receive EOF when the (last) writing descriptor is closed, i.e. here when awk ends. Does awk linger for some reason (e.g. because sqsh does not finish and awk's input is still open)? Check with ps from another terminal. Commented Nov 5, 2015 at 23:00

1 Answer 1

1

You don't need to do anything special. When awk reaches EOF on its input, it will execute its END block (if there is one) and then exit, and this will close the pipe. That will then cause the next process in the pipeline to read EOF.

If you want the awk script to send EOF earlier than that, it will have to exit, by using the exit statement.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, You're right. The reason of fail isn't lack of EOF. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.