I have a script and I receive data from stdin as an argument separated by newlines say I have
string1,string2
string3,string4
And I want to take sperately string1,string2
and string3,string4
.
But I receive an unknown number of such lines, my script only reads the first 2 and then stops. I tried parsing \n
from stdin but it does not work.How should I approach this?
I tried reading like this
for i in "$@"
do
var1=$(echo "$i" | cut -f2 -d,)
var2=$(echo "$i" | cut-f2 -d,)
#etc
What I am actually trying to accomplish is say I have a file input.txt
with that type of input:
string1,string2
string3,string4
If I do cat input.txt | ./myscript.sh
I want to take, no matter how many lines of strings I have I want to take each line and extract from it in 2 variables stringI,stringJ
respectively.
for i in "$@" do var1=$(echo "$i" | cut -f2 -d,) var2=$(echo "$i" | cut-f2 -d,)
– C. Cristi Nov 22 '18 at 07:19