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

Clash 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-
bash shell-script
add a comment |Â
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-
bash shell-script
@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 containsncharacters?
â terdonâ¦
Dec 15 '17 at 18:49
@terdon I specified the missing information.
â Thodi
Dec 15 '17 at 19:13
add a comment |Â
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-
bash shell-script
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-
bash shell-script
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 containsncharacters?
â terdonâ¦
Dec 15 '17 at 18:49
@terdon I specified the missing information.
â Thodi
Dec 15 '17 at 19:13
add a comment |Â
@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 containsncharacters?
â 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
add a comment |Â
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!
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 thatRS=""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.awkwould be much faster and have a lower risk of silent data loss
â thrig
Dec 18 '17 at 15:23
add a comment |Â
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!
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 thatRS=""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.awkwould be much faster and have a lower risk of silent data loss
â thrig
Dec 18 '17 at 15:23
add a comment |Â
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!
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 thatRS=""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.awkwould be much faster and have a lower risk of silent data loss
â thrig
Dec 18 '17 at 15:23
add a comment |Â
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!
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!
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 thatRS=""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.awkwould be much faster and have a lower risk of silent data loss
â thrig
Dec 18 '17 at 15:23
add a comment |Â
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 thatRS=""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.awkwould 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@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
ncharacters?â terdonâ¦
Dec 15 '17 at 18:49
@terdon I specified the missing information.
â Thodi
Dec 15 '17 at 19:13