0

head testregions.bed

21      15390708       
21      15890068        16388793
21      16390041        16888505
21      16889055        17388185
21      17388731        17886839

I wanted to use each line of the .bed file as outputname e.g:

while readline  
do zip.sh > 21_15390708_ 15889554.zip
            21_16390041-16888505.zip

I read a bit about xargs being able to do this. But I am stuck on how it can output each line to unique output file name.

xargs -a testregions.bed -I {} zip inputfile {} >> outputfile_{}.zip

and so on. Any help is much appreciated.

1
  • I tried with below command and achieved as below let me know for any modifications awk '{print $1""$2""$3}' p.txt output :21_15390708_ 21_15890068_16388793 21_16390041_16888505 21_16889055_17388185 21_17388731_17886839 Dec 6, 2019 at 14:49

1 Answer 1

0

Here is an easy-to-understand way you can do this for every line in your testregions.bed. First, delete all the whitespace in your original file testregions.bed and save just the numbers into a new file new.txt like this:

cat testregions.bed | tr -d "[:blank:]" > new.txt

Then, you will create a new file for each line in your new.txt like this:

cat new.txt | while read line do touch "$line".zip done

And then you can delete the new.txt:

rm new.txt

So your script test.sh to create .zip files of testregions.bed would look like this:

#!/bin/sh

cat testregions.bed | tr -d "[:blank"]" > new.txt
cat new.txt | while read line
do
        touch "$line".zip
done
rm new

You must log in to answer this question.

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