LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-16-2012, 05:37 AM   #1
Adzrules
LQ Newbie
 
Registered: Oct 2012
Posts: 14

Rep: Reputation: Disabled
Remove lines based upon the previous line


Hi everyone,

I have the following text in a document:

Code:
LF82_762
F0 	GCGGATTTTATTTTATTAAG
LF82_784	
LF82_539	
F0	ATGAGTAAGCGGATGCATTCTC
R0	AGTTCAGAAGCTGAAGCAGAAA
LF82_2826	
F0	ATGGATTTCGACACAATCATGGA
R0	AGCCGTTAGATTTTGCCGA
LF82_672
LF82_749
LF82_3653	
R0	AAATTATTTTATTAAGTGTAAAACAGTTAACGACTATCGC
LF82_442
F0	ATGTTCGCGGGATCGTGTGGGTCGATGC
I would like to remove any lines that are NOT followed by a line containing an F0 AND then a line with an R0, so that the resulting text looks like this:

Code:
LF82_539	
F0	ATGAGTAAGCGGATGCATTCTC
R0	AGTTCAGAAGCTGAAGCAGAAA
LF82_2826	
F0	ATGGATTTCGACACAATCATGGA
R0	AGCCGTTAGATTTTGCCGA
I initially thought of using awk, but the syntax is a bit confusing. Any suggestions?

Thank you to all

Adzrules
 
Old 11-16-2012, 05:49 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Logic first and syntax later. Sketch your state machine on a piece of paper starting from a "start" state where you have opened the file but not done anything yet. Then the program in awk or something else will start to become clear.
 
Old 11-16-2012, 06:18 AM   #3
mandyapenguin
Member
 
Registered: Nov 2011
Location: India
Distribution: RedHat, Cent OS, Fedora, Debian, Ubuntu
Posts: 106

Rep: Reputation: Disabled
This may help you
Code:
sed '/^FO*\|^RO*/!d' filename
 
  


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
Copying lines from multiple logfiles, based on content of the line Larss Programming 2 10-30-2012 01:10 PM
Remove many lines based on content of other file anderssk Programming 13 06-23-2011 10:34 AM
Perl script to replace a line after finding a previous line Mark1986 Programming 1 02-28-2011 05:09 PM
[SOLVED] How to remove line breaks from lines ending with a comma jasonws Linux - General 1 11-10-2010 12:03 PM
Attempting to append a line of text to the end of the previous line market_garden Linux - General 4 12-11-2008 11:37 AM

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

All times are GMT -5. The time now is 01:43 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
Open Source Consulting | Domain Registration