I have a file I want to parse:
mmu-miR-15-5p/16-5p/195-5p/424-5p/497-5p 0610007P14Rik
mmu-miR-326-3p/330-5p 0610007P14Rik
mmu-miR-326-3p/330-5p Lmir
mmu-miR-15/16/195/424/497 0610007P14Rik
mmu-miR-15-5p/16-5p/195-5p/424-5p/497-5p/6838-5p 0610007P14Rik
mmu-miR-15/16/195/424-5p/497 Alinf
mmu-miR-326/330-5p 0610007P14Rik
mmu-miR-326/330 0610007P14Rik
mmu-miR-1/206/613 Crgi
mmu-miR-1-3p/206 0610007P14Rik
the desired output:
for the first line
mmu-miR-15-5p 0610007P14Rik
mmu-miR16-5p 0610007P14Rik
mmu-miR195-5p 0610007P14Rik
mmu-miR424-5p 0610007P14Rik
mmu-miR497-5p 0610007P14Rik
and so on...
I just need to replace /
with mmu-miR
and create a new line along with their second column.
I tried with following one line code on bash:
sed 's/\//\nmmu-miR/g' test.txt
mmu-miR-15-5p
mmu-miR16-5p
mmu-miR195-5p
mmu-miR424-5p
mmu-miR497-5p 0610007P14Rik
mmu-miR-326-3p
mmu-miR330-5p 0610007P14Rik
mmu-miR-326-3p
mmu-miR330-5p Lmir
I tried to use a while
loop and this sed command:
while read line; do
lineCols=( $line );
v1=($(echo "${lineCols[0]}"));
v2=($(echo "${lineCols[1]}"));
sed 's/\//\n/g' ${v1};
done <test.txt
but got an error:
sed: can't read mmu-miR-15-5p/16-5p/195-5p/424-5p/497-5p: No such file or directory
sed: can't read mmu-miR-326-3p/330-5p: No such file or directory
sed: can't read mmu-miR-326-3p/330-5p: No such file or directory
sed: can't read mmu-miR-15/16/195/424/497: No such file or directory
sed: can't read mmu-miR-15-5p/16-5p/195-5p/424-5p/497-5p/6838-5p: No such file or directory
What am I doing wrong?
while read line; echo ...
constructs (see here for further details). Furthermore, this looks like a job more suited forawk
thansed
, but that might be a pretty subjective matter. – Valentin B. Nov 14 '16 at 17:38