chippycentra
chippycentra

Reputation: 3432

Fill a argument with tab file values in bash

I need to creat a bash file in order to run a certain command on a server.

Here is one of the lines

Programm/programm.pl -k 1 -q --acc_number 

where --acc_number needs a Comma-separated list of accession numbers, e.g. --acc_number Number13JJ2,Number0090D93,Number088DF.

but I actually have a file calle file_acc_number where I have each of the accession number in line such as :

Number13JJ2
Number0090D93
Number088DF

does someone have an idea how to parse this tab file and to directly put the accessio number in a comma-separated way and get :

Programm/programm.pl -k 1 -q --acc_number Number13JJ2,Number0090D93,Number088DF

Thank you for your help

Upvotes: 1

Views: 54

Answers (2)

carrotcakeslayer
carrotcakeslayer

Reputation: 1008

with an inline expansion maybe? Like this

Programm/programm.pl -k 1 -q --acc_number  $(sed -z 's/\n/,/g' file_acc_number)

Make sure your file "file_acc_number" has no "new line" at the end of it.

With this, you will replace the "new line" character with a comma on the fly without affecting the original file.

Upvotes: 1

Fazlin
Fazlin

Reputation: 2337

Try using paste:

Programm/programm.pl -k 1 -q --acc_number `paste -s -d, file_acc_number`

Try running paste -s -d, file_acc_number first to understand whether you get what you require.

Upvotes: 3

Related Questions