Read script until delimiter and echo result that is piped for command

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a cypher script that consists of multiline cypher queries that are delimited by a specific string e.g. -delmiter-.



I want to echo each of these segments into the cypher shell in a container and get the query that was sent into the cypher shell and the output of the shell.



When using dummy code it would be like this



#!/bin/bash
while read $multilinesegment
do
echo $multilinesegment
docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose
done <<< import.cypher #-delimitedby'-delimiter-'


How can I split the script into these segments and run a loop with it?



edit:
My import.cypher looks like this:



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-






share|improve this question






















  • @maulinglawns sorry I wasn't finished with my question yet. I hope my edit cleares things up?
    – Thodi
    Dec 15 '17 at 18:26






  • 2




    Please also i) show us an example of your input; ii) tell us what shell you are using. You had tagged this as Ubuntu but that can easily mean either dash or bash or something else; and iii) clarify why you are calling your variable "multiline". Is this going to be a string that contains n characters?
    – terdon♦
    Dec 15 '17 at 18:49











  • @terdon I specified the missing information.
    – Thodi
    Dec 15 '17 at 19:13














up vote
0
down vote

favorite












I have a cypher script that consists of multiline cypher queries that are delimited by a specific string e.g. -delmiter-.



I want to echo each of these segments into the cypher shell in a container and get the query that was sent into the cypher shell and the output of the shell.



When using dummy code it would be like this



#!/bin/bash
while read $multilinesegment
do
echo $multilinesegment
docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose
done <<< import.cypher #-delimitedby'-delimiter-'


How can I split the script into these segments and run a loop with it?



edit:
My import.cypher looks like this:



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-






share|improve this question






















  • @maulinglawns sorry I wasn't finished with my question yet. I hope my edit cleares things up?
    – Thodi
    Dec 15 '17 at 18:26






  • 2




    Please also i) show us an example of your input; ii) tell us what shell you are using. You had tagged this as Ubuntu but that can easily mean either dash or bash or something else; and iii) clarify why you are calling your variable "multiline". Is this going to be a string that contains n characters?
    – terdon♦
    Dec 15 '17 at 18:49











  • @terdon I specified the missing information.
    – Thodi
    Dec 15 '17 at 19:13












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a cypher script that consists of multiline cypher queries that are delimited by a specific string e.g. -delmiter-.



I want to echo each of these segments into the cypher shell in a container and get the query that was sent into the cypher shell and the output of the shell.



When using dummy code it would be like this



#!/bin/bash
while read $multilinesegment
do
echo $multilinesegment
docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose
done <<< import.cypher #-delimitedby'-delimiter-'


How can I split the script into these segments and run a loop with it?



edit:
My import.cypher looks like this:



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-






share|improve this question














I have a cypher script that consists of multiline cypher queries that are delimited by a specific string e.g. -delmiter-.



I want to echo each of these segments into the cypher shell in a container and get the query that was sent into the cypher shell and the output of the shell.



When using dummy code it would be like this



#!/bin/bash
while read $multilinesegment
do
echo $multilinesegment
docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose
done <<< import.cypher #-delimitedby'-delimiter-'


How can I split the script into these segments and run a loop with it?



edit:
My import.cypher looks like this:



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-
match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;
-delimiter-








share|improve this question













share|improve this question




share|improve this question








edited Dec 15 '17 at 19:12

























asked Dec 15 '17 at 18:20









Thodi

12




12











  • @maulinglawns sorry I wasn't finished with my question yet. I hope my edit cleares things up?
    – Thodi
    Dec 15 '17 at 18:26






  • 2




    Please also i) show us an example of your input; ii) tell us what shell you are using. You had tagged this as Ubuntu but that can easily mean either dash or bash or something else; and iii) clarify why you are calling your variable "multiline". Is this going to be a string that contains n characters?
    – terdon♦
    Dec 15 '17 at 18:49











  • @terdon I specified the missing information.
    – Thodi
    Dec 15 '17 at 19:13
















  • @maulinglawns sorry I wasn't finished with my question yet. I hope my edit cleares things up?
    – Thodi
    Dec 15 '17 at 18:26






  • 2




    Please also i) show us an example of your input; ii) tell us what shell you are using. You had tagged this as Ubuntu but that can easily mean either dash or bash or something else; and iii) clarify why you are calling your variable "multiline". Is this going to be a string that contains n characters?
    – terdon♦
    Dec 15 '17 at 18:49











  • @terdon I specified the missing information.
    – Thodi
    Dec 15 '17 at 19:13















@maulinglawns sorry I wasn't finished with my question yet. I hope my edit cleares things up?
– Thodi
Dec 15 '17 at 18:26




@maulinglawns sorry I wasn't finished with my question yet. I hope my edit cleares things up?
– Thodi
Dec 15 '17 at 18:26




2




2




Please also i) show us an example of your input; ii) tell us what shell you are using. You had tagged this as Ubuntu but that can easily mean either dash or bash or something else; and iii) clarify why you are calling your variable "multiline". Is this going to be a string that contains n characters?
– terdon♦
Dec 15 '17 at 18:49





Please also i) show us an example of your input; ii) tell us what shell you are using. You had tagged this as Ubuntu but that can easily mean either dash or bash or something else; and iii) clarify why you are calling your variable "multiline". Is this going to be a string that contains n characters?
– terdon♦
Dec 15 '17 at 18:49













@terdon I specified the missing information.
– Thodi
Dec 15 '17 at 19:13




@terdon I specified the missing information.
– Thodi
Dec 15 '17 at 19:13










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Can -delimiter- be a blank line?



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

...


If so



awk 'BEGIN 
RS=""
command = "docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose"

print ' import.cypher


and then you do not need the (slow and) bad at reading lines while read loop. Bad in the sense that if the ultimate line lacks a newline, that line is



(echo one; echo -n two) | while read l; do echo $l; done


whoops! silent data loss!






share|improve this answer




















  • Is there a way to use a specific delimiter?
    – Thodi
    Dec 16 '17 at 14:24










  • yes, but it complicates the code as you will likely need to switch to line-by-line parsing and accumulating not delimiter lines, etc that RS="" in paragraph mode already gives you
    – thrig
    Dec 16 '17 at 15:44










  • line by line parsing would be a while read loop, correct?
    – Thodi
    Dec 18 '17 at 10:05










  • no, that would be the bad slow way. awk would be much faster and have a lower risk of silent data loss
    – thrig
    Dec 18 '17 at 15:23










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f411108%2fread-script-until-delimiter-and-echo-result-that-is-piped-for-command%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Can -delimiter- be a blank line?



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

...


If so



awk 'BEGIN 
RS=""
command = "docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose"

print ' import.cypher


and then you do not need the (slow and) bad at reading lines while read loop. Bad in the sense that if the ultimate line lacks a newline, that line is



(echo one; echo -n two) | while read l; do echo $l; done


whoops! silent data loss!






share|improve this answer




















  • Is there a way to use a specific delimiter?
    – Thodi
    Dec 16 '17 at 14:24










  • yes, but it complicates the code as you will likely need to switch to line-by-line parsing and accumulating not delimiter lines, etc that RS="" in paragraph mode already gives you
    – thrig
    Dec 16 '17 at 15:44










  • line by line parsing would be a while read loop, correct?
    – Thodi
    Dec 18 '17 at 10:05










  • no, that would be the bad slow way. awk would be much faster and have a lower risk of silent data loss
    – thrig
    Dec 18 '17 at 15:23














up vote
0
down vote













Can -delimiter- be a blank line?



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

...


If so



awk 'BEGIN 
RS=""
command = "docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose"

print ' import.cypher


and then you do not need the (slow and) bad at reading lines while read loop. Bad in the sense that if the ultimate line lacks a newline, that line is



(echo one; echo -n two) | while read l; do echo $l; done


whoops! silent data loss!






share|improve this answer




















  • Is there a way to use a specific delimiter?
    – Thodi
    Dec 16 '17 at 14:24










  • yes, but it complicates the code as you will likely need to switch to line-by-line parsing and accumulating not delimiter lines, etc that RS="" in paragraph mode already gives you
    – thrig
    Dec 16 '17 at 15:44










  • line by line parsing would be a while read loop, correct?
    – Thodi
    Dec 18 '17 at 10:05










  • no, that would be the bad slow way. awk would be much faster and have a lower risk of silent data loss
    – thrig
    Dec 18 '17 at 15:23












up vote
0
down vote










up vote
0
down vote









Can -delimiter- be a blank line?



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

...


If so



awk 'BEGIN 
RS=""
command = "docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose"

print ' import.cypher


and then you do not need the (slow and) bad at reading lines while read loop. Bad in the sense that if the ultimate line lacks a newline, that line is



(echo one; echo -n two) | while read l; do echo $l; done


whoops! silent data loss!






share|improve this answer












Can -delimiter- be a blank line?



match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

match (a:Person)-[:Is_maried_to]-(b)
set b.last_name=a.last_name
return a,b;

...


If so



awk 'BEGIN 
RS=""
command = "docker exec -i neo4j_container /bin/cypher-shell -u user -p password --format=verbose"

print ' import.cypher


and then you do not need the (slow and) bad at reading lines while read loop. Bad in the sense that if the ultimate line lacks a newline, that line is



(echo one; echo -n two) | while read l; do echo $l; done


whoops! silent data loss!







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 15 '17 at 20:26









thrig

22.4k12852




22.4k12852











  • Is there a way to use a specific delimiter?
    – Thodi
    Dec 16 '17 at 14:24










  • yes, but it complicates the code as you will likely need to switch to line-by-line parsing and accumulating not delimiter lines, etc that RS="" in paragraph mode already gives you
    – thrig
    Dec 16 '17 at 15:44










  • line by line parsing would be a while read loop, correct?
    – Thodi
    Dec 18 '17 at 10:05










  • no, that would be the bad slow way. awk would be much faster and have a lower risk of silent data loss
    – thrig
    Dec 18 '17 at 15:23
















  • Is there a way to use a specific delimiter?
    – Thodi
    Dec 16 '17 at 14:24










  • yes, but it complicates the code as you will likely need to switch to line-by-line parsing and accumulating not delimiter lines, etc that RS="" in paragraph mode already gives you
    – thrig
    Dec 16 '17 at 15:44










  • line by line parsing would be a while read loop, correct?
    – Thodi
    Dec 18 '17 at 10:05










  • no, that would be the bad slow way. awk would be much faster and have a lower risk of silent data loss
    – thrig
    Dec 18 '17 at 15:23















Is there a way to use a specific delimiter?
– Thodi
Dec 16 '17 at 14:24




Is there a way to use a specific delimiter?
– Thodi
Dec 16 '17 at 14:24












yes, but it complicates the code as you will likely need to switch to line-by-line parsing and accumulating not delimiter lines, etc that RS="" in paragraph mode already gives you
– thrig
Dec 16 '17 at 15:44




yes, but it complicates the code as you will likely need to switch to line-by-line parsing and accumulating not delimiter lines, etc that RS="" in paragraph mode already gives you
– thrig
Dec 16 '17 at 15:44












line by line parsing would be a while read loop, correct?
– Thodi
Dec 18 '17 at 10:05




line by line parsing would be a while read loop, correct?
– Thodi
Dec 18 '17 at 10:05












no, that would be the bad slow way. awk would be much faster and have a lower risk of silent data loss
– thrig
Dec 18 '17 at 15:23




no, that would be the bad slow way. awk would be much faster and have a lower risk of silent data loss
– thrig
Dec 18 '17 at 15:23












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f411108%2fread-script-until-delimiter-and-echo-result-that-is-piped-for-command%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)