LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Insert new line help (https://www.linuxquestions.org/questions/linux-newbie-8/insert-new-line-help-4175440476/)

ShiGua 12-07-2012 01:19 PM

Insert new line help
 
So I have a file that contains

Code:

>NM_#########AUGCAUCGUAGCUAGUCGAUACUGGACUG>NM_########AUGAGUAUGUAUGAUGUAUGUAUGA
where # is any digit 0-9 (the text is many repetitions of the pattern above, not just that, but all in one line), and I want it to show

Code:

>NM_#########
AUGUAGUGCUAGCUGAUCGAUGCUAGUCGUAGC
>NM_########
AGUGAGUCGUCGUGACUGACUGUGGCAUCGUA

Basically I need to add a new line before every > and between a number and a letter.

OR

If it's easier, I have something like this

Code:

>NM_#########
AUGCUGAC
GACGUAGC
ACGUGUAG
>NM_########
AGUGCUGA
ACGUAGCU
ACGUGCUA

and I want to condense all the letter only lines to one line, like the output shown above.

If someone could help me how to do this with a simple command, it would really help.

Thank you!

druuna 12-07-2012 01:38 PM

Have a look at this:
Code:

$ echo '>NM_12345AUGCAUCGUAGCUAGUCGAUACUGGACUG>NM_987654321AUGAGUAUGUAUGAUGUAUGUAUGA' | \
sed -r 's/>NM_([0-9]+)/\n>NM_\1\n/g'

>NM_12345
AUGCAUCGUAGCUAGUCGAUACUGGACUG
>NM_987654321
AUGAGUAUGUAUGAUGUAUGUAUGA


colucix 12-07-2012 01:44 PM

Or
Code:

$ sed -r 's/[AUGCT]+/\n&\n/g' file
>NM_7675435267
AUGCAUCGUAGCUAGUCGAUACUGGACUG
>NM_76532650
AUGAGUAUGUAUGAUGUAUGUAUGA

$

with an extra newline at the end.

druuna 12-07-2012 02:03 PM

@colucix: Nice.

And if this has to do with DNA/RNA codons then yours might be preferable, I am assuming That the NM_ part is static.....


All times are GMT -5. The time now is 05:50 PM.