How to separate output of variables [closed]
up vote
0
down vote
favorite
I want to write a script to separate outputs. Output should be like this:
192.168.94.139
middle of loop
192.168.94.140
middle of loop
After separating to the new line I want to run some commands before execute other one.
My code,
for INPUT in $SERVER_SELECTION
do
echo $INPUT | tr , 'n'
echo "middle of loop "
done
echo "end of loop "
How can I modify this to take above output.
bash scripts
closed as unclear what you're asking by Soren A, guiverc, steeldriver, Zanna, Eric Carvalho Dec 6 at 16:27
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
I want to write a script to separate outputs. Output should be like this:
192.168.94.139
middle of loop
192.168.94.140
middle of loop
After separating to the new line I want to run some commands before execute other one.
My code,
for INPUT in $SERVER_SELECTION
do
echo $INPUT | tr , 'n'
echo "middle of loop "
done
echo "end of loop "
How can I modify this to take above output.
bash scripts
closed as unclear what you're asking by Soren A, guiverc, steeldriver, Zanna, Eric Carvalho Dec 6 at 16:27
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I have some inputs in "SERVER_SELECTION" variable those are 192.168.94.139, 192.168.94.140. When I use variable to get the output it prints as in a line. Then I usedtr , 'n'
command to separate lines. But I want execute some commands under 192.168.94.139 and also 192.168.94.140.
– Janith
Dec 5 at 8:07
1
put IFS=',' before "for" and remove "tr" command, this should split SERVER_SELECTION and INPUT will contains one ip at once
– Lety
Dec 5 at 9:50
It works fine, then how to run some scripts by taking particular ip address?
– Janith
Dec 5 at 11:11
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to write a script to separate outputs. Output should be like this:
192.168.94.139
middle of loop
192.168.94.140
middle of loop
After separating to the new line I want to run some commands before execute other one.
My code,
for INPUT in $SERVER_SELECTION
do
echo $INPUT | tr , 'n'
echo "middle of loop "
done
echo "end of loop "
How can I modify this to take above output.
bash scripts
I want to write a script to separate outputs. Output should be like this:
192.168.94.139
middle of loop
192.168.94.140
middle of loop
After separating to the new line I want to run some commands before execute other one.
My code,
for INPUT in $SERVER_SELECTION
do
echo $INPUT | tr , 'n'
echo "middle of loop "
done
echo "end of loop "
How can I modify this to take above output.
bash scripts
bash scripts
edited Dec 5 at 18:37
Zanna
49.4k13128236
49.4k13128236
asked Dec 5 at 6:46
Janith
697
697
closed as unclear what you're asking by Soren A, guiverc, steeldriver, Zanna, Eric Carvalho Dec 6 at 16:27
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Soren A, guiverc, steeldriver, Zanna, Eric Carvalho Dec 6 at 16:27
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I have some inputs in "SERVER_SELECTION" variable those are 192.168.94.139, 192.168.94.140. When I use variable to get the output it prints as in a line. Then I usedtr , 'n'
command to separate lines. But I want execute some commands under 192.168.94.139 and also 192.168.94.140.
– Janith
Dec 5 at 8:07
1
put IFS=',' before "for" and remove "tr" command, this should split SERVER_SELECTION and INPUT will contains one ip at once
– Lety
Dec 5 at 9:50
It works fine, then how to run some scripts by taking particular ip address?
– Janith
Dec 5 at 11:11
add a comment |
I have some inputs in "SERVER_SELECTION" variable those are 192.168.94.139, 192.168.94.140. When I use variable to get the output it prints as in a line. Then I usedtr , 'n'
command to separate lines. But I want execute some commands under 192.168.94.139 and also 192.168.94.140.
– Janith
Dec 5 at 8:07
1
put IFS=',' before "for" and remove "tr" command, this should split SERVER_SELECTION and INPUT will contains one ip at once
– Lety
Dec 5 at 9:50
It works fine, then how to run some scripts by taking particular ip address?
– Janith
Dec 5 at 11:11
I have some inputs in "SERVER_SELECTION" variable those are 192.168.94.139, 192.168.94.140. When I use variable to get the output it prints as in a line. Then I used
tr , 'n'
command to separate lines. But I want execute some commands under 192.168.94.139 and also 192.168.94.140.– Janith
Dec 5 at 8:07
I have some inputs in "SERVER_SELECTION" variable those are 192.168.94.139, 192.168.94.140. When I use variable to get the output it prints as in a line. Then I used
tr , 'n'
command to separate lines. But I want execute some commands under 192.168.94.139 and also 192.168.94.140.– Janith
Dec 5 at 8:07
1
1
put IFS=',' before "for" and remove "tr" command, this should split SERVER_SELECTION and INPUT will contains one ip at once
– Lety
Dec 5 at 9:50
put IFS=',' before "for" and remove "tr" command, this should split SERVER_SELECTION and INPUT will contains one ip at once
– Lety
Dec 5 at 9:50
It works fine, then how to run some scripts by taking particular ip address?
– Janith
Dec 5 at 11:11
It works fine, then how to run some scripts by taking particular ip address?
– Janith
Dec 5 at 11:11
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
put IFS=','
before for
and remove tr
command, this should split SERVER_SELECTION
and INPUT
will contains one ip at once.
IFS=','
for INPUT in $SERVER_SELECTION
do
echo $INPUT
<path to script> $INPUT # call other script and use INPUT as parameter
echo "middle of loop "
done
echo "end of loop"
IFS stands for "internal field separator". It is used by the shell to determine how to do word splitting, i. e. how to recognize word boundaries.
This worked for me. Thank you so much. Is there a alternative toIFS
command?
– Janith
Dec 5 at 11:30
add a comment |
up vote
0
down vote
I don't know what exactly your trying to do but merely doing this:
echo "$INPUT"
echo "middle of loop "
should produce that result. Again maybe a read
from file is what you want! Then you should do
while read -r INPUT
do
echo "$INPUT"
echo "middle of loop "
done < "$SERVER_SELECTION"
echo "end of loop "
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
put IFS=','
before for
and remove tr
command, this should split SERVER_SELECTION
and INPUT
will contains one ip at once.
IFS=','
for INPUT in $SERVER_SELECTION
do
echo $INPUT
<path to script> $INPUT # call other script and use INPUT as parameter
echo "middle of loop "
done
echo "end of loop"
IFS stands for "internal field separator". It is used by the shell to determine how to do word splitting, i. e. how to recognize word boundaries.
This worked for me. Thank you so much. Is there a alternative toIFS
command?
– Janith
Dec 5 at 11:30
add a comment |
up vote
1
down vote
accepted
put IFS=','
before for
and remove tr
command, this should split SERVER_SELECTION
and INPUT
will contains one ip at once.
IFS=','
for INPUT in $SERVER_SELECTION
do
echo $INPUT
<path to script> $INPUT # call other script and use INPUT as parameter
echo "middle of loop "
done
echo "end of loop"
IFS stands for "internal field separator". It is used by the shell to determine how to do word splitting, i. e. how to recognize word boundaries.
This worked for me. Thank you so much. Is there a alternative toIFS
command?
– Janith
Dec 5 at 11:30
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
put IFS=','
before for
and remove tr
command, this should split SERVER_SELECTION
and INPUT
will contains one ip at once.
IFS=','
for INPUT in $SERVER_SELECTION
do
echo $INPUT
<path to script> $INPUT # call other script and use INPUT as parameter
echo "middle of loop "
done
echo "end of loop"
IFS stands for "internal field separator". It is used by the shell to determine how to do word splitting, i. e. how to recognize word boundaries.
put IFS=','
before for
and remove tr
command, this should split SERVER_SELECTION
and INPUT
will contains one ip at once.
IFS=','
for INPUT in $SERVER_SELECTION
do
echo $INPUT
<path to script> $INPUT # call other script and use INPUT as parameter
echo "middle of loop "
done
echo "end of loop"
IFS stands for "internal field separator". It is used by the shell to determine how to do word splitting, i. e. how to recognize word boundaries.
answered Dec 5 at 11:27
Lety
4,93521730
4,93521730
This worked for me. Thank you so much. Is there a alternative toIFS
command?
– Janith
Dec 5 at 11:30
add a comment |
This worked for me. Thank you so much. Is there a alternative toIFS
command?
– Janith
Dec 5 at 11:30
This worked for me. Thank you so much. Is there a alternative to
IFS
command?– Janith
Dec 5 at 11:30
This worked for me. Thank you so much. Is there a alternative to
IFS
command?– Janith
Dec 5 at 11:30
add a comment |
up vote
0
down vote
I don't know what exactly your trying to do but merely doing this:
echo "$INPUT"
echo "middle of loop "
should produce that result. Again maybe a read
from file is what you want! Then you should do
while read -r INPUT
do
echo "$INPUT"
echo "middle of loop "
done < "$SERVER_SELECTION"
echo "end of loop "
add a comment |
up vote
0
down vote
I don't know what exactly your trying to do but merely doing this:
echo "$INPUT"
echo "middle of loop "
should produce that result. Again maybe a read
from file is what you want! Then you should do
while read -r INPUT
do
echo "$INPUT"
echo "middle of loop "
done < "$SERVER_SELECTION"
echo "end of loop "
add a comment |
up vote
0
down vote
up vote
0
down vote
I don't know what exactly your trying to do but merely doing this:
echo "$INPUT"
echo "middle of loop "
should produce that result. Again maybe a read
from file is what you want! Then you should do
while read -r INPUT
do
echo "$INPUT"
echo "middle of loop "
done < "$SERVER_SELECTION"
echo "end of loop "
I don't know what exactly your trying to do but merely doing this:
echo "$INPUT"
echo "middle of loop "
should produce that result. Again maybe a read
from file is what you want! Then you should do
while read -r INPUT
do
echo "$INPUT"
echo "middle of loop "
done < "$SERVER_SELECTION"
echo "end of loop "
edited Dec 5 at 7:36
answered Dec 5 at 7:28
George Udosen
19.1k94266
19.1k94266
add a comment |
add a comment |
I have some inputs in "SERVER_SELECTION" variable those are 192.168.94.139, 192.168.94.140. When I use variable to get the output it prints as in a line. Then I used
tr , 'n'
command to separate lines. But I want execute some commands under 192.168.94.139 and also 192.168.94.140.– Janith
Dec 5 at 8:07
1
put IFS=',' before "for" and remove "tr" command, this should split SERVER_SELECTION and INPUT will contains one ip at once
– Lety
Dec 5 at 9:50
It works fine, then how to run some scripts by taking particular ip address?
– Janith
Dec 5 at 11:11