LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 11-28-2011, 02:34 AM   #1
Lokelo
LQ Newbie
 
Registered: Nov 2011
Location: Townsville
Posts: 15

Rep: Reputation: Disabled
Separating interleaved lines into two different files


After managing to solve a few minor programming issues on my own (I assume in a rather crude way, but they work) I got stuck with another problem I'm not really sure how to solve.

I have a file with interleaved data:

Code:
@HWI-ST261:396:I0D48ABXX:8:1101:1354:2103/1
ATCCGATTGGATTAACATAGTGCTACACTTAATAGATGCCGTTGGCCTCCTCCCAACGAGACTTGACTTTAGTCT
+
HHJJJIJJIJIJJJJJIJIJIIJJIJJJJJIGIIIIIJJJJIIGGHIJJJJIHGIJHHFFEFEECEEDDDDDDDE
@HWI-ST261:396:I0D48ABXX:8:1101:1354:2103/2
CCTCGCGCGTGTGCCTTTCTGGAACGGCAAAGATTCGGAAGCGATGAAGAACGCGGAAAGGACCAAGGAGATGAT
+
HHJJJJJJJHHHIJIJJJJJJJIIHHIJJJJJJJJIHHHHFFDDDDDCDDDD=BBBDD>ABDDDDDDDBB?>@C@
@HWI-ST261:396:I0D48ABXX:8:1101:1536:2081/1
CTCCACCCACCCGATCGTGCAGCACAACTCTTACACTGCCTGGTTTGCAGAGGGAGAGGCAAGCGAGGCGCAGCT
+
HHJIJJJJJJJJJIJJHBGHIJJJJIHGIIIIJIIGEHHHGEF@DFCEEECDBBBB?B@BDD????<@><5<<@A
@HWI-ST261:396:I0D48ABXX:8:1101:1536:2081/2
GTGCGAGGAGGAAGACATTGGAGAAGACGGAGAACTGCACGACGAGCTCCCTCAGCTGCGCCTCGCTTGCCTCTC
+
HFHIJGIJEIJGGHEHIJJJJIJIGIJIHJJIIAFHIJJHIJHHFDBDDDDDD?CD>CDDB@>BDD<ABBCCCCC
@HWI-ST261:396:I0D48ABXX:8:1101:1721:2085/1
CCAGCGACATTTTCGAACGTTACTGGGTCGTTCTTCACATCTCGTGGACCATCAAATGGCTCCATGGAGCAATCG
+
HHGHGHGIIIHIIIGIIIIHIGIIIIIGHIII@GGAC==@CGGCCAEDDF<@C;>;;>CDDDBCC(>@AA(5>CB
@HWI-ST261:396:I0D48ABXX:8:1101:1721:2085/2
GCTCGAGCACCATGTGGACATCGTCAAGCTGAAGGACTGCCAGTGCGACTTGCAGCCAGAGTTTGTCGATTGCTC
+
HHJJIJIGIJJCHIIIIIJGGHHCGIIJJGHHIJGIIJIDHHIIIIIJIFHFHDDB?>@BC6>CDDD8?8>7:55
@HWI-ST261:396:I0D48ABXX:8:1101:1861:2094/1
GCCTCGCTCGCCTTCTTGCGAACCACCTTCTTCCCATCATTGCTATCACCACTATTGCCATCCTTCGAGTCCTTC
+
HHJIJJGIJJJJJJIGIJGIJIEIIIIIIIIIHHIJIFHFHHHEEECCEC@CECCDDDDDCDDDDCABC>CCDDC
@HWI-ST261:396:I0D48ABXX:8:1101:1861:2094/2
CGAACTTGTTCGATGACAATCAGACATTCGCCGGCTCTTTCATGCCCATCTTTGGTAAGGGTGACCCGATCATTA
+
HHGIIIIIHJJJGGJJJJJJJJJIJJIJJJJHHGHEGHIHIGJJHHHHHFFFFFFDC>AC?=BBDDDDDBBB>@A
The lines starting with @HWI are the ID of the data in the next 3 lines, so every 4 lines are one data entry.

I would like to have all the data of the ID's ending in /1 in one file and with /2 in another file and they need to be in the exact same order.

I know I can pull out single lines with awk and grep, but I'm not sure how I could pull out the following three lines, too.
 
Old 11-28-2011, 03:07 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Here's a "dirty", but working solution:
Code:
#!/bin/bash

awk '
/^@HWI.*\/1/ { print > "file1"
  getline ; print  > "file1"
  getline ; print  > "file1"
  getline ; print > "file1"
}
/^@HWI.*\/2/ { print > "file2"
  getline ; print  > "file2"
  getline ; print  > "file2"
  getline ; print > "file2"
}
' infile
Hope this helps.
 
1 members found this post helpful.
Old 11-28-2011, 03:26 AM   #3
Lokelo
LQ Newbie
 
Registered: Nov 2011
Location: Townsville
Posts: 15

Original Poster
Rep: Reputation: Disabled
It seems to work just fine! thanks!
 
Old 11-28-2011, 03:33 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
  


Reply



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
Comparing lines in two files? needhelp12 Linux - Newbie 3 11-12-2011 11:48 PM
Interleaved/Multichannel audio programming with ALSA on linux-2.6.23.9 kernel Mohan.Sundram Linux - Kernel 0 08-27-2008 05:31 AM
delete lines from files bharatbsharma Programming 5 10-25-2007 08:43 AM
reading non-interleaved raw data performance problem James_dean Programming 1 01-26-2006 12:20 AM
Extracting Lines from files supreme_command Linux - Newbie 1 05-12-2004 04:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:29 AM.

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
Open Source Consulting | Domain Registration