Split table into new table from each single row

Viewed 20

I have an output file that looks like this

head -10 names.txt

AAACCCAAGTGATAAC-1  AAACCCAAGTGATAAC-1
AAACCCACACATTCTT-1  AAACCCACACATTCTT-1
AAACCCACAGTGGCTC-1  AAACCCACAGTGGCTC-1
AAACCCAGTCCCGCAA-1  AAACCCAGTCCCGCAA-1
AAACCCAGTGACTCTA-1  AAACCCAGTGACTCTA-1
AAACCCAGTGGGATTG-1  AAACCCAGTGGGATTG-1
AAACCCAGTTCCAAAC-1  AAACCCAGTTCCAAAC-1
AAACCCATCCATTCGC-1  AAACCCATCCATTCGC-1
AAACCCATCTGTAAGC-1  AAACCCATCTGTAAGC-1
AAACGAAAGAGTCAGC-1  AAACGAAAGAGTCAGC-1

I want to split it so that for each row I get a text file that looks like this

head AAACCCAAGTGATAAC-1.txt
AAACCCAAGTGATAAC-1  AAACCCAAGTGATAAC-1

I then want to run a command in a loop that uses one of those files every time. how can I do that?

sinto filterbarcodes -b possorted_genome_bam.bam -c i.txt -p 8

what would be the best practice to do it?

1 Answers

as LHLaurini said, split can do it. I have add file extensions after that. Here is the output, just for reference.

gxie@devenv:~/workspace/test $ split -l 1 names.txt names-
gxie@devenv:~/workspace/test $ ls -l names-*
-rw-r--r-- 1 gxie linseeusers_5g_hz 39 Sep 22 12:52 names-aa
-rw-r--r-- 1 gxie linseeusers_5g_hz 39 Sep 22 12:52 names-ab
-rw-r--r-- 1 gxie linseeusers_5g_hz 39 Sep 22 12:52 names-ac
gxie@devenv:~/workspace/test $ for file in names-*; do mv "$file" "${file}.txt"; done
gxie@devenv:~/workspace/test $ ls -l names-*
-rw-r--r-- 1 gxie linseeusers_5g_hz 39 Sep 22 12:52 names-aa.txt
-rw-r--r-- 1 gxie linseeusers_5g_hz 39 Sep 22 12:52 names-ab.txt
-rw-r--r-- 1 gxie linseeusers_5g_hz 39 Sep 22 12:52 names-ac.txt
Related