Merge multiple lines in one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge multiple lines in one line
# 1  
Old 01-31-2013
Merge multiple lines in one line

Hi guys,

So i have a input file with several sequences aligned (fasta)

Code:
>NC_005930 241 bp
MNMINIFIINNIFDQFIPVKLSIFSLTSVGSIIA
LSWVWINTKTHWAISRSNTP-SLLLNSL
WTLLITNL-NEKTNPWAPWLFSLFLLCFSFNIMSLI-PYTF-SQ
TSHLSFTFGLSLPIWIMVNIAGFKNNWKKKISHLLPQGTPIYLVPVMII
IETISLFIQPLTLGFRLGANLLAGHLLIFLCSCTIWE
AINYNIYL-GTISFSLILVLLILEIAVAFIQATVFLILSKNYLEENIN-
>NC_000425 241 bp
MNMINIFIINNIFDQFIPVKLSIFSLTSVGSIIA
LSWVWINTKTHWAISRSNTP-SLLLNSL
WTLLITNL-NEKTNPWAPWLFSLFLLCFSFNIMSLI-PYTF-SQ
TSHLSFTFGLSLPIWIMVNIAGFKNNWKKKISHLLPQGTPIYLVPVMII
IETISLFIQPLTLGFRLGANLLAGHLLIFLCSCTIWE
AINYNIYL-GTISFSLILVLLILEIAVAFIQATVFLILSKNYLEENIN-
.
.
.

and i want get on output:

Code:
>NC_005930 241 bp
MNMINIFIINNIFDQFIPVKLSIFSLTSVGSIIALSWVWINTKTHWAISRSNTPSLLLNSLWTLLITNLNEKTNPWAPWLFSLFLLCFSFNIMSLIPYTFSQTSHLSFTFGLSLPIWIMVNIAGFKNNWKKKISHLLPQGTPIYLVPVMIIIETISLFIQPLTLGFRLGANLLAGHLLIFLCSCTIWEAINYNIYLGTISFSLILVLLILEIAVAFIQATVFLILSKNYLEENIN-
>NC_000425 241 bp
MNMINIFIINNIFDQFIPVKLSIFSLTSVGSIIALSWVWINTKTHWAISRSNTPSLLLNSLWTLLITNLNEKTNPWAPWLFSLFLLCFSFNIMSLIPYTFSQTSHLSFTFGLSLPIWIMVNIAGFKNNWKKKISHLLPQGTPIYLVPVMIIIETISLFIQPLTLGFRLGANLLAGHLLIFLCSCTIWEAINYNIYLGTISFSLILVLLILEIAVAFIQATVFLILSKNYLEENIN-
.
.
.

I have tried perl and shell script with s/\n//; only for the sequence but i dont get the correct output!

Thanks for the help Smilie

Andreia
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 01-31-2013 at 06:52 PM.. Reason: code tags, please!
# 2  
Old 01-31-2013
try:
Code:
awk '/^>/;!/^>/ {printf}' infile

# 3  
Old 01-31-2013
Code:
awk '/^>/ { print ((FNR==1)?"":ORS) $0;next} {printf $0}' myFile


Last edited by vgersh99; 01-31-2013 at 07:06 PM.. Reason: ooops...
# 4  
Old 01-31-2013
Code:
awk '/^>/&&NR==1{print;next}/^>/&&NR!=1{printf "\n%s\n",$0;}!/^>/{printf "%s",$0}END{printf "\n"}' filename

# 5  
Old 01-31-2013
You implied that you just want to merge lines, but most (but not all) minus signs in your input file were removed.

Please explain what determines whether a minus sign found on an input line is supposed to be copied to an output line.
# 6  
Old 01-31-2013
Thanks for the answers ...

yes, the minus sign (on sequence) needs to include on search like if was an similar letter A-Z ... its a fasta sequence aligned so its normal when protein/nucleotide sequence gets minus sign ...
# 7  
Old 01-31-2013
Quote:
Originally Posted by andreia
Thanks for the answers ...

yes, the minus sign (on sequence) needs to include on search like if was an similar letter A-Z ... its a fasta sequence aligned so its normal when protein/nucleotide sequence gets minus sign ...
I'm sorry, but biology was not my major. Please explain how a program reading your input file is supposed to know which minus signs should be removed when merging input lines. (None of the provided scripts produce the output you said you wanted because the output you said you want to get drops five out of six minus signs in the second line of each output pair.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge multiple lines into a single line

Hi all, I'm relatively new to scripting, I can do pretty basic things. I have a daily log file that looks like: timestamp=2017-06-28-01.01.35.080576; event status=0; userid=user1; authid=user1; application id=10.10.10.10.11111.12345678901; application name=GUI; ... (29 Replies)
Discussion started by: dwdnet
29 Replies

2. UNIX for Dummies Questions & Answers

How to merge every n lines into one line?

I want to merge every 16 lines into one line, how can I do that? My file looks like below: 0 . 2 2 . 0 0 . 0 0 . 0 0 . 0 0 0 0 0 (2 Replies)
Discussion started by: ml4me
2 Replies

3. Shell Programming and Scripting

Merge multiple lines to one line when line starts with and ends with

example: comment Now_TB.table column errac is for error messages 1 - first 2 - second 3 -third ; in this example I need to be able to grab the comment as first word and ; as the last word and it might span a few lines. I need it to be put all in one line without line breaks so I can... (4 Replies)
Discussion started by: wambli
4 Replies

4. Shell Programming and Scripting

Merge multiple lines in same file with common key using awk

I've been a Unix admin for nearly 30 years and never learned AWK. I've seen several similar posts here, but haven't been able to adapt the answers to my situation. AWK is so damn cryptic! ;) I have a single file with ~900 lines (CSV list). Each line starts with an ID, but with different stuff... (6 Replies)
Discussion started by: protosd
6 Replies

5. UNIX for Dummies Questions & Answers

To merge a few lines to 1 line

Hi Experts, This is my input file. input.txt 0 /dev/fd 25 /var 1 /tmp 1 /var/run 1. If this file has single line, then leave it, print the single line else merge the 4 lines above into 1 line as below e.g (6 Replies)
Discussion started by: streddy
6 Replies

6. Shell Programming and Scripting

Using Perl to Merge Multiple Lines in a File

I've hunted and hunted but nothing seems to apply to what I need. Any help will be much appreciated! My input file looks like (Unix): marker,allele1,allele2 RS1002244,1,1 RS1002244,1,3 RS1002244,3,3 RS1003719,2,2 RS1003719,2,4 RS1003719,4,4 Most markers are listed 3 times but a few... (2 Replies)
Discussion started by: Peggy White
2 Replies

7. Shell Programming and Scripting

merge multi-lines into one line

Hi, Can anyone help me for merge the following multi-line logs( the black lines) which beginning with time: into one line. For the line with "-", it needs to be deleted. Please see the red color line. ######################################### time: 20080817073334 dn: uid=ok,ou=nbt... (3 Replies)
Discussion started by: missyou
3 Replies

8. Shell Programming and Scripting

Removing end of line to merge multiple lines

I'm sure this will be an easy question for you experts out there, but I have been searching the forum and working on this for a couple hours now and can't get it right. I have a very messy data file that I am trying to tidy up - one of the issues is some records are split into multiple lines: ... (4 Replies)
Discussion started by: tink
4 Replies

9. Shell Programming and Scripting

merge multiple lines from flat file

Hi, I have a tab delimited flat file like this: 189 Guide de lutilisateur sur lappel conférence à trois au moyen d'adaptateurs téléphoniques <TABLE><TBODY><TR><TD><DIV class=subheader>La fonction Appel conférence à trois </DIV></TD> \ <TD><?php print $navTree;?> vous permet de tenir un appel... (4 Replies)
Discussion started by: hnhegde
4 Replies

10. Shell Programming and Scripting

Use sed to merge multiple lines

Hi all: I have a file in which the contents are as following: ... This is a test ONE TWO Hello, world! XXX YYY CCC test again three, four five six seven world AAA BBB QQQ test eight, nine world (3 Replies)
Discussion started by: xb88
3 Replies
Login or Register to Ask a Question