Score:0

bash pipe multiple outputs as input to other command

in flag

I am noob with shell script and I am trying to pass multiple arguments to an command. I have a urls.txt file that looks as below

name1,http://url1
name2,http://url2
name3,http://url3
name4,http://url4

with the below command I am able to get output after splitting by comma

cat urls.txt | cut -d ',' -f1
cat urls.txt | cut -d ',' -f2

The first one gives the name1, name2, etc and second one gives http://url1 http://url2. what I wanted to do was pipe both of them as a variable to a third command where I can use both of them.

Any ideas or suggestions are highly appreciated?

Bodo avatar
pt flag
This looks like a shell script question, not specifically related to Ubuntu. You might want to ask this question on https://stackoverflow.com/. Please explain what you want to achieve. What does your "third command" do? Your description "pipe both of them as a variable to a third command" does not make much sense. The terms *pipe* and * variable* are different things. A pipe is a data stream which can be split into lines or words.
Bodo avatar
pt flag
see [BashFAQ/001](https://mywiki.wooledge.org/BashFAQ/001#Field_splitting.2C_whitespace_trimming.2C_and_other_input_processing)
Score:2
ca flag
$ while IFS=, read nam url ;do echo "name:$nam, url:$url" ; done <urls.txt 
name:name1, url:http://url1
name:name2, url:http://url2
name:name3, url:http://url3
name:name4, url:http://url4
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.