LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 04-09-2009, 06:06 AM   #1
aditi_borkar
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
Unhappy Compare two fields on consecutive rows and print the two rows


Hi, I have been trying really hard to get this done. I have an input (I have removed extra lines) that looks like the following:

LC 1 C:G 24 -0.42 5.56 37.77 -0.19 0.54 3.48
LC 2 G:C 23 1.52 -5.21 35.68 0.65 0.54 3.43
LC 3 C:G 22 2.71 7.44 31.80 -0.01 0.95 3.44
LC 4 G:C 21 0.23 6.00 33.00 -0.23 0.10 3.40
LC 5 A:T 20 -1.35 2.32 37.16 -0.08 -0.16 3.13
LC 6 A:T 19 -1.04 2.17 34.61 -0.03 -0.61 3.32
LC 7 T:A 18 0.18 0.17 36.30 0.01 -0.28 3.26
LC 8 T:A 17 1.51 0.77 37.68 0.01 0.04 3.36
LC 9 C:G 16 -1.84 -0.91 30.29 0.30 1.16 3.45
LC 10 G:C 15 -1.56 -5.19 38.79 -0.93 0.85 3.52
LC 11 C:G 14 2.00 2.15 38.46 0.40 0.61 3.45
LC 12 G:C 13

From these 12 rows, I just want to extract the consecutive rows pairwise that will contain C:G in the first row and G:C in the second row. 4 such combinations can be seen in the lines that I have printed above (1 and 2, 3 and 4, 9 and 10 and 11 and 12). Thus, my output should look like:

LC 1 C:G 24 -0.42 5.56 37.77 -0.19 0.54 3.48
LC 2 G:C 23 1.52 -5.21 35.68 0.65 0.54 3.43
LC 3 C:G 22 2.71 7.44 31.80 -0.01 0.95 3.44
LC 4 G:C 21 0.23 6.00 33.00 -0.23 0.10 3.40
LC 9 C:G 16 -1.84 -0.91 30.29 0.30 1.16 3.45
LC 10 G:C 15 -1.56 -5.19 38.79 -0.93 0.85 3.52
LC 11 C:G 14 2.00 2.15 38.46 0.40 0.61 3.45
LC 12 G:C 13

I have many such input files and it is difficult to manually extract the desired rows.
 
Old 04-09-2009, 06:27 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You can try awk:
Code:
$3 ~ "C:G" {
  first = $0
  getline
  if ( $3 ~ "G:C" ) {
    print first
    print $0
  }
}
 
Old 04-09-2009, 06:37 AM   #3
aditi_borkar
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanx a lot!!

I had been trying something similar, but it did not work. This script solves my purpose.
 
Old 04-09-2009, 06:49 AM   #4
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: /root
Distribution: Slackware & BSD
Posts: 1,220

Rep: Reputation: 231Reputation: 231Reputation: 231
aditi_borkar:

What is the type of input?

If you mean a text file containing those lines you can easily extract the needed "G:C" or "C:G" lines therefrom and save it into a file. Use the terminal.

$ grep 'C:G' ./input.txt >./myGCfile
$ cat myGCfile

there you got them into one file.

Try expound more of your problem so that others in the forum will understand what you need and they might be able to help you the better than what I gave here.

Hope this helps. Goodluck.
 
  


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
How to print data in rows and columns suran Linux - General 3 03-15-2009 03:53 PM
cutting rows having particular pattern adidassharma Programming 1 10-06-2008 08:02 AM
Column into rows bharatbsharma Programming 1 10-25-2007 03:23 AM
columns & rows Ammad Linux - General 1 08-08-2005 05:02 AM
rows and columns digitalgravy Linux - General 2 03-16-2004 07:47 PM


All times are GMT -5. The time now is 04:26 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration