joining multi-line file into single lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting joining multi-line file into single lines
# 1  
Old 08-29-2012
joining multi-line file into single lines

Hi,

I have a file like mentioned below..For each specific id starting with > I want to join the sequence in multiple lines to a single line..Is there a simple way in awk or sed to do this

Code:
>ENST00000558922 cdna:KNOWN
TCCAGGATCCAGCCTCCCGATCACCGCGCTAGTCCTCGCCCTGCCTGGGCTTCCCCAGAG
ACGGGAGCTTGGGTGGGGGACCCTGGACCCGAAGCCAAGGCTGAACTGGTGTGCCAAGCC
CAGGGAGCAACCAAGTCCCCAACTCTTTCCCTGCCCTTCCCGCAGGCTGAGCAGAAAACC
AGGAAATGGATGGACTCCACCTCCGCAGCCACGCCTGCCCGTTTGCGCTTACTGAACAGA
GGTCCTCAGGAACGTGAAAATGAAGGGAGGGTTACTAACTTTATGCCATCTTCAAACCAG
AAGATCTTAGATTAGTAAGATCATGTTGGCCATGGCATGGAGAATGGGCTGGAGGTGGAG
AGACTGGAGGTTGGAAGTCCAGTTAGGAGATTGCTCCTGCGCTGGGGAGTTGGTGTTAGG
ACAGAAGATCCAAGACGCGTTTCAGAGAGCCCCTCTTCTTGGGCCTGCGATTCCTCACCT
GGAAGGGAGAAGAGTGGACTTCCTGCCTAGAGAACACCTTGGTAAACTCTTTGTGGTTCC
>ENST00088352 cdna:UNKNOWN
TGTCATGAGAAGGTGTGCAGCTTAGGGAAAAAGCCTGTGAGCTCTGGAATCAGATGGAAC
TGGATATGAATTTCCATTTAAACTGCCTTGGGGTTCATGTTGCAGCATCAAACAGGGATG
GAAGATGCATCTTGCTTTAGCAGCAGGAGCCTGGAAAGCAGCTGAAGCCCTGGAGGGTGC
CTGGCACACAGAATCTTGTGCTGAGCCCGGAGCACAATGGGAGCGGGCTGGCGGGGTGGG
TTCACAGCTGGACTGGGAGCAGCAGACATACAGGCCGTAGGCACAGACATATAAAGACAG
TCATGCAGATTGCAGGATGCCTGAGAGCACAGACTCTCACATGCACAAATACGTGCATGA
TCGCCAGTGTGCATCCAGACAGCCCCACATGCATGCACACGCATGCACACATGTGATGTG
TACATAGATGGACACATGTCTATGCCCACAAACACTGCAGAGACACAG

Thanks,

Last edited by Diya123; 08-29-2012 at 03:48 PM..
# 2  
Old 08-29-2012
Try:
Code:
awk ' /^>/ {if (FNF>1){ printf("\n")}} {printf("%s", $0) }' infile > newfile

# 3  
Old 08-29-2012
Not sure if you want all in one single line as jim_mcnamara's proposal does or in one line per id. This is a bit ugly but it does it the second way:
Code:
sed -n '/^>/{x;s/\n//g;1!p;d}; /^[^>]/H; ${x;s/\n//g;p}' infile

If you want the id in an extra line, this will do:
Code:
sed -n '/^>/{x;s/\n//g;1!p;s/.*//g;x;p}; /^[^>]/H; ${x;s/\n//g;p}' infile


Last edited by RudiC; 08-29-2012 at 05:28 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merge multi-lines into one single line using shell script or Linux command

Hi, Can anyone help me for merge the following multi-line log which beginning with a " and line ending with ": into one line. *****Original Log***** 087;2008-12-06;084403;"mc;;SYHLR6AP1D\LNZW;AD-703;1;12475;SYHLR6AP1B;1.1.1.1;0000000062;HGPDI:MSISDN=12345678,APNID=1,EQOSID=365;... (3 Replies)
Discussion started by: rajeshlinux2010
3 Replies

2. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

3. Shell Programming and Scripting

Multi lines to single line

HI, My input file contains the data as like below: A1234119993 B6271113 Bghjkjk A1234119992 B6271113hi Bghjkjkmkl the output i require is : A1234119993 B6271113 Bghjkjk A1234119992 B6271113hi Bghjkjkmkl Please help me in this. Thanks (6 Replies)
Discussion started by: pandeesh
6 Replies

4. UNIX for Dummies Questions & Answers

Alphabetical sort for multi line records contains in a single file

Hi all, I So, I've got a monster text document comprising a list of various company names and associated info just in a long list one after another. I need to sort them alphabetically by name... The text document looks like this: Company Name: the_first_company's_name_here Address:... (2 Replies)
Discussion started by: quee1763
2 Replies

5. Shell Programming and Scripting

Multi line document to single lines based on occurance of string

Hi Guys, I am new to awk and sed, i am working multiline document, i want to make make that document into SINGLE lines based on occurace of string "dwh". here's the sample of my problem.. dwh123 2563 4562 4236 1236 78956 12394 4552 dwh192 2656 46536 231326 65652 6565 23262 16625623... (5 Replies)
Discussion started by: victor369
5 Replies

6. Shell Programming and Scripting

Joining contents in multiple lines to a single line

I do have a file with contents splited into multiple lines ADSLHLJASHGLJSKAGHJJGAJSLGAHLSGHSAKBV AJHALHALHGLAGLHGBJVFBJVLFDHADAH GFJAGJAGAJFGAKGAKGFAK AJHFAGAKAGAGKAKAKGKAGFGJDGDJJDGJDJDFAG ... ... .... 100's of lines I would like to rearrange the content of this file so it will be a... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

7. Shell Programming and Scripting

Help on Merge multi-lines into one single line

Hello, Can anyone let me know how to use Perl script to Merge following multi-lines into one single line... ***** Multi-line***** FILE_Write root OK Tue Jul 01 00:00:00 2008 cl_get_path file descriptor = 1 FILE_Write root OK ... (5 Replies)
Discussion started by: happyday
5 Replies

8. Shell Programming and Scripting

Merge multi-lines into one single line

Hi, Can anyone help me for merge the following multi-line log which beginning with a number and time: into one line. For each line need to delete the return and add a space. Please see the red color line. *****Original Log*****... (4 Replies)
Discussion started by: happyday
4 Replies

9. Shell Programming and Scripting

joining 2 lines into single one

i have a script that joins 2 lines of a file into one line and again next 2 line into one line. if number of line is 4 then after joining it should be 2 lines in a file my file a1.txt has some of the below lines 1-GH32X, CC, AMR, Number of Intervals Not Inserted: 1 / 95 1-150KP1, CC,... (3 Replies)
Discussion started by: ali560045
3 Replies

10. UNIX for Dummies Questions & Answers

Joining lines to single line in VI

Dear friends, In VI, I have these data shown below: Line1 Line2 Line3 Line4 How can I JOIN these line to the first line? When I finished I should have: Line1 Line2 Line3 Line4 is there a text length limit of how long a single line can be in VI? Thank you much! (10 Replies)
Discussion started by: bobo
10 Replies
Login or Register to Ask a Question