I have a pipe that gives me lines of two quoted space separated strings. Using echo to give you an example of the pipe content:
echo -e "\"filename1\" \"some text 1\"\n\"filename2\" \"some text 2\""
"filename1" "some text 1"
"filename2" "some text 2"
First string is a filename and the second is the text I want to append to that file. Getting the handle to $filename and $text with "read" is easy:
echo -e "\"filename1\" \"some text 1\"\n\"filename2\" \"some text 2\""|
while read filename text; do echo $text $filename; done
"some text 1" "filename1"
"some text 2" "filename2"
but "parallel" doesn't want to treat the two strings on the line as two parameters. It seems to treat them as one.
echo -e "\"filename1\" \"some text 1\"\n\"filename2\" \"some text 2\""|
parallel echo {2} {1}
"filename1" "some text 1"
"filename2" "some text 2"
So just having {1} on the line gives the same result
echo -e "\"filename1\" \"some text 1\"\n\"filename2\" \"some text 2\""|
parallel echo {1}
"filename1" "some text 1"
"filename2" "some text 2"
Adding --colsep ' '
makes it break the strings on every space
echo -e "\"filename1\" \"some text 1\"\n\"filename2\" \"some text 2\""|
parallel --colsep ' ' echo {2} {1}
"some "filename1"
"some "filename2"
I just could not find the explanation on how to handle this case through the pipe to parallel in its documentation https://www.gnu.org/software/parallel/man.html
Adding a --delimiter ' '
option gives this
echo -e "\"filename1\" \"some text 1\"\n\"filename2\" \"some text 2\""|
parallel --delimiter ' ' echo {2} {1}
"filename1"
"some
text
1"
"filename2"
"some
text
2"
This is the closest I have found
seq 10 | parallel -N2 echo seq:\$PARALLEL_SEQ arg1:{1} arg2:{2}
seq:1 arg1:1 arg2:2
seq:2 arg1:3 arg2:4
seq:3 arg1:5 arg2:6
seq:4 arg1:7 arg2:8
seq:5 arg1:9 arg2:10
but it doesn't really reflect my data as seq 10
has a new line after each string and I have two strings on the line.
1
2
3
4
5
6
7
8
9
10
My current workaround is just to change the pipe to have a comma instead of a space to separate the quoted strings on a line:
echo -e "\"filename1\",\"some text 1\"\n\"filename2\",\"some text 2\""|
parallel --colsep ',' echo {2} {1}
"some text 1" "filename1"
"some text 2" "filename2"
But how to handle this with parallel?