I am using xargs
in conjunction with cut
, but I am unsure how to get the output of cut
to a variable that I can pipe to use for further processing.
So, I have a text file like so:
test.txt
:
/some/path/to/dir,filename.jpg
/some/path/to/dir2,filename2.jpg
...
I do this:
cat test.txt | xargs -L1 | cut -d, -f 1,2
/some/path/to/dir,filename.jpg
but what Id like to do is:
cat test.txt | xargs -L1 | cut -d, -f 1,2 | echo $1 $2
where $1
and $2
are /some/path/to/dir
and filename.jpg
.
I am stumped that I cannot seem to able to achieve this.
What I want to achieve is:
read_somehow_the text_fields_from text_file | ./mypgm -i $1 -o $2
xargs -L1
is not really doing anything for you here sincecut
operates line-by-line anyway. How about something likewhile IFS=, read x y; do echo "\$x is $x and \$y is $y"; done < test.txt
instead? – steeldriver Mar 15 '22 at 12:44To split fields by spaces instead of commas can be done by
– White Owl Mar 15 '22 at 12:47tr
, or just the simplecut -f1,2 -d, --output-delimiter ' ' file
will be sufficient.