I need to write a script with the following behaviour:
$ echo $'one&some text\ntwo&other text' | ./my_script.sh --delimiter &
Line:
1st: one
2nd: some tex
Line:
1st: two
2nd: other text
Which can be also called with the default delimiter which is \t
:
$ echo $'one\tsome text\nfive\tother text' | ./my_script.sh
Output should be the same as above.
Script should take input via standard in.
What is the easiest way to do this? Possibly in pure bash.
I've tried this approach but it does not work and I don't know why:
while read -r line
do
echo "$line"
IFS=$DELIMITER
arr=(${line//$DELIMITER/ })
echo ${arr[0]}
echo ${arr[1]}
done