print lines AFTER lines cointaining a regexp (or print every first and fourth line)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print lines AFTER lines cointaining a regexp (or print every first and fourth line)
# 1  
Old 07-06-2010
print lines AFTER lines cointaining a regexp (or print every first and fourth line)

Hi all,

This should be very easy but I can't figure it out...

I have a file that looks like this:
Code:
@SRR057408.1 FW8Y5CK02R652T length=34
AGCAGTGGTATCAACGCAGAGTAAGCAGTGGTAT
+SRR057408.1 FW8Y5CK02R652T length=34
FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8
@SRR057408.2 FW8Y5CK02TBMHV length=52
CGTTGATACCACTGCTTACTCTGCGTTGATACCACTGCTTACTCTGCGTTGA
+SRR057408.2 FW8Y5CK02TBMHV length=52
FIIIIIFEDFCCEF<<<EFFFFGGGFFFFA:::AA@A<0004<889<422=7
@SRR057408.3 FW8Y5CK02R8Z08 length=72
CTCTGCGTTGATACCACTGCTTACTTCTGCGTTGATACCACTGCTTAACTCTGCGTTGGATACACTGCTTAC
+SRR057408.3 FW8Y5CK02R8Z08 length=72
FIIIIIIIIIIFFFFFDDFA:::D998@A??<844432125774----/158::85522443433=::91//
@SRR057408.4 FW8Y5CK02R76ED length=49
ATACCACTGCTTACTCTGCGTTGATACCACTGCTTACTCTGCGTTGATA
+SRR057408.4 FW8Y5CK02R76ED length=49
FIIIIIIIII@@@HIIIHFFFFHHFFFFFFFDDBBBBA=89444484//

I want to print every first and fourth line so that the output looks like this:
Code:
@SRR057408.1 FW8Y5CK02R652T length=34
FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8
@SRR057408.2 FW8Y5CK02TBMHV length=52
FIIIIIFEDFCCEF<<<EFFFFGGGFFFFA:::AA@A<0004<889<422=7
@SRR057408.3 FW8Y5CK02R8Z08 length=72
FIIIIIIIIIIFFFFFDDFA:::D998@A??<844432125774----/158::85522443433=::91//
@SRR057408.4 FW8Y5CK02R76ED length=49
FIIIIIIIII@@@HIIIHFFFFHHFFFFFFFDDBBBBA=89444484//

No matter what I try along the lines of
Code:
sed -n '1,${p;n;n}'

, I can't get it to work. I'm sure there is an easy to specify the printing of every first and fourth line only but for future reference, how would I specify "print lines after lines beginning with a plus sign?"

Thanks,
Kevin

---------- Post updated at 08:34 PM ---------- Previous update was at 08:14 PM ----------

Well I finally figured this much out:
Code:
sed -n '1~4p;4~4p' demo.fastq

# 2  
Old 07-06-2010
Code:
sed -n 'p;n;n;n;p'

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print number of lines for files in directory, also print number of unique lines

I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with: wc -l *|sort 15263 Image.txt 16401 reference.txt 40459 richtexteditor.txt How can I also print the number of unique lines in each file? 15263 1401 Image.txt 16401... (15 Replies)
Discussion started by: spacegoose
15 Replies

2. Shell Programming and Scripting

Print multiple lines on one line

Hi All, I have a file looks like: rst:singh:99.0.20-X86 2 rst:ACSI_SIN_SERVICES rst:singh:99.0.20-X86 2 rst:ACSI_BISI want to wrap 3rd col in one line and add variable value at start and ending of line and I wrote command: cat file | awk '{print $3}' | xargs > command.txt sed -e... (1 Reply)
Discussion started by: rakeshtomar82
1 Replies

3. Shell Programming and Scripting

Print the first line for each multiple lines

Hi all, i need help to extract each first line from multiple lines occurrences based on different patterns (name) starting from the fourth lines like follows:- // header 1 header 2 header 3 // no acc name score rank //... (2 Replies)
Discussion started by: redse171
2 Replies

4. Shell Programming and Scripting

sed print first line before regexp and all lines after

Hi All I'm trying to extract the line just above a regexp and all lines after this. I'm currently doing this in two steps sed -n -e "/^+---/{g;p;}" -e h oldfile.txt > modified.txt sed -e "1,/^+---/d" -e "/^$/d" oldfile.txt >>modified.txt Sample sometext will be here sometext will be... (3 Replies)
Discussion started by: Celvin VK
3 Replies

5. Shell Programming and Scripting

Print lines between a regExp & a blank line

Hi, I have a file, say files_list, as below (o/p of ls -R cmd) $ cat files_list /remote/dir/path/to/file: sub-dir1 sub-dir2 sub-dir3 ... /remote/dir/path/to/file/sub-dir1: remote_file1.csv.tgz <blank line 1> /remote/dir/path/to/file/sub-dir2: remote_file2.csv.tgz <blank... (3 Replies)
Discussion started by: dips_ag
3 Replies

6. Shell Programming and Scripting

print lines between line number

Hi, Anyone help me to print the lines from the flat file between 879th line number and 1424th line number. The 879 and 1424 should be passed as input to the shell script(It should be dynamic). Can any one give me using sed or awk? I tried using read, and print the lines..Its taking too... (3 Replies)
Discussion started by: senthil_is
3 Replies

7. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

8. Shell Programming and Scripting

print 2 lines above regexp

I am on a Solaris 10 x86 system sample code before3 before2 before1 group after1 after2 after3 I want to grab the second line above my regexp regexp=group I want to grab ONLY the before2 line I have numerous sed and awk ways of grabbing X line below the regexp, but no luck... (1 Reply)
Discussion started by: snoman1
1 Replies

9. UNIX for Dummies Questions & Answers

grep N lines after match and then print them on 1 line each

Hello I have a silly question. I need to grep a match in text file and then print 5 lines after it. grep -A 5 .... do it. OK The next thing I can not handle is I need each output to be on 1 line match line2 line3 line4 line5 match line2 line3 line4 line5 etc.. I will really... (10 Replies)
Discussion started by: alekkz
10 Replies

10. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies
Login or Register to Ask a Question