LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-07-2012, 01:19 PM   #1
ShiGua
LQ Newbie
 
Registered: Nov 2012
Posts: 5

Rep: Reputation: Disabled
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!
 
Old 12-07-2012, 01:38 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
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
 
Old 12-07-2012, 01:44 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Or
Code:
$ sed -r 's/[AUGCT]+/\n&\n/g' file
>NM_7675435267
AUGCAUCGUAGCUAGUCGAUACUGGACUG
>NM_76532650
AUGAGUAUGUAUGAUGUAUGUAUGA

$
with an extra newline at the end.
 
1 members found this post helpful.
Old 12-07-2012, 02:03 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
@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.....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Insert line using sed or awk at line using line number as variable sunilsagar Programming 11 02-03-2012 10:48 AM
[SOLVED] Insert paragraph at particular line sunilsagar Programming 4 07-27-2011 10:33 PM
How do I insert a line/value after a particular line, in file with sed Glenn D. Programming 3 01-21-2010 09:14 PM
sed insert line action_owl Linux - Newbie 3 08-24-2009 12:06 AM
insert a line or a file to /etc j-me Linux - Newbie 9 07-23-2009 01:47 PM


All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration