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


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?

  • This looks like a shell script question, not specifically related to Ubuntu. You might want to ask this question on 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
    Jan 14, 2022 at 16:14
  • 1
    see BashFAQ/001
    – Bodo
    Jan 14, 2022 at 16:16

1 Answer 1

$ 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .