How to print line starting with certain string together with its following line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print line starting with certain string together with its following line?
# 1  
Old 03-12-2014
How to print line starting with certain string together with its following line?

Dear all,

How can I print line starting with certain string together with its following line. Example is as follows:

Input file:

Code:
@M01596:22:000000000-A7YH7:1:1101:16615:1070 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNCAAGGTATTATAAGCCGTACAGGTGCCGTCGCGTACTCGCGTGAAACTCCTATCCTCTCCTGCTCGGCATTCGAATTCAGGTCGTGCT
+
###############################################################:9:FFFGGGGGGGGGGGGGGGGDGGGGGGEFGGGGGGGEFGGDEGGFFGGGGGG8EF;BFGCGCFGCGGDGGEGCFGGGGGGGGGDE8
--
@M01596:22:000000000-A7YH7:1:1101:19605:1070 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTTCAGAGTAACACCGGAAAGCGTTACCGCTAATTGTTGAGCACGATGCCAATCACGGCGATGTTCGAATTATTGTTGTGCTCGCTACA
+
###############################################################::DFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGFGGGGGGGGGGGGGGGGGGGGGGGGD
--
@M01596:22:000000000-A7YH7:1:1101:9956:1070 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGCCGGGCAATAATGTTTATGTTGGTTTCATGGTTTGGTCTAACTTTACCGCTACTAAATGCCGCGGATTGGTTTCGCTGAATCAGGTT
+
###############################################################::CFGGGGGGFGGGGGGGGGGGGGGGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG7EGGGGGGGGGGGGGGCFGGGGG
--
@M01596:22:000000000-A7YH7:1:1101:21195:1071 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTCCTCAAGGCGTCAGTATTGTTGAAGTTGTGTCCATCAGGGAGGTGACAATGAATTTCTGCTGTGCTCGCTACAGACTCGGACAGATC
+
###############################################################::DFFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGEGGGGGGGGGFFFEGGGGGGG
--
@M01596:22:000000000-A7YH7:1:1101:12710:1082 2:N:0:1
NNNNNCANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTCAAATCCGGCGTCAACCATACCAGCAGAGGAAGCATCAGCACCAGCACGCTCCCAAGCATTAAGCTCAGGAAATGCAGCAGCAAGAT
+
#####==########################################################9:,:CF6B6+FECGCFFEFFFGEFCFD<FGFEGGGGGDG<E9?FFGGEECED@FFGF@CFCFFGDEFG9EEEDGGF9EFCEB,@DFF>
--
@M01596:22:000000000-A7YH7:1:1101:21487:1088 2:N:0:1
NNCTNACNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGAGAGGCCGGGGCATTTTCCGCTGCGGTTGGGACGGGAGAGGCCAGGGGCGTGCCATCGAGCACTACTGGAGAAAAATGATCTTTGCT
+
##88#=C########################################################::@<CFCFEFGGG7FCFGDEC7:C7=FCGGGG8AFGG7F:FGEDEGCF@GCEGEFGGGEGFCGGGFFA9DDFGGFGGGG;,@ECGGFF
--
@M01596:22:000000000-A7YH7:1:1101:11107:1088 2:N:0:1
NNATNATNTNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTCGCTGCGTTGAGGCTTGCGTTTATGGTACGCTGGACTTTGTAGGATACCCTCGCTTTCCTGCTCCTGTTGAGTTTATTGCTGCCGTC
+
##8A#=C#=######################################################:9CFDFCFFFEGGFGFGCGDGGGCGFDFFFGGDGGG?EEEFGGGFCFGFEFBCGGGGCFGGFFEGGEFFFGGDFGA=FG9EFGGFGGD
--
@M01596:22:000000000-A7YH7:1:1101:11149:1092 2:N:0:1
GACTNACGANNNNNANCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNCCACGCTGCGTCACCGAGCTAATCCCAGTATGACACCATTGTTCTTCTACCACATGCATTCTGAATTGTCGATGTGCTCGCTACAGAC
+
CCCC#=CFG#####=#=##############################################::DFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGFGGGGGGEGGGGGGFFGDGGGGGGG
--
@M01596:22:000000000-A7YH7:1:1101:16931:1092 2:N:0:1
CATGNACTTNNNNNANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTACAGTAGAGTCAATAGCAAGGCCACGACGCAATGGAGAAAGACGGAGAGCGCCAACGGCGTCCATCTCGAAGGAGTCGCCAGCGATA
+
B-@@#:CFG#####,################################################::CFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGDGGGGGGGGGGGGGGGGGGCGCEGD
--
@M01596:22:000000000-A7YH7:1:1101:10051:1093 2:N:0:1
CTTCNTCCTNNTNNTNTNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTTGCTACTGACCGCTCTCGTGCTCGTCGCTGCGTTGAGGCTTGCGTTTATGGTACGCTGGACTTTGTAGGATACCCTCGCTTTCCTGC
+
CCCC#,=C,##=##,#=##############################################::6FGGGGGGGGCGGGGGDGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGFCGGGGGGFGFGGGFGGGGGGGFGGGGGGGGGFE
--
@M01596:22:000000000-A7YH7:1:1101:12072:1097 2:N:0:1
GACTNACGACTGNNANCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGTTGTGCTCGCTACAGACTCGGACAGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGTATCATTAAAAAA
+
CCCC#:CFFGGG##=#=##############################################::CEGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCFFGGG
--
@M01596:22:000000000-A7YH7:1:1101:21840:1098 2:N:0:1
GACTNACGACTGNNANCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTATAGAATTGTTACTGTGCTCGCTACAGACTCGGACAGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGT
+
CCCC#=CFGGGG##=#=##############################################6:CFGGFEGGGGGGGGFFGGGGDEGGGGGGGGFGGGGGGCF=FEEGGFEG:FGGDGGGGGGGGGG8EEE@EGGGGG8=EGG69>EGG3
--
@M01596:22:000000000-A7YH7:1:1101:14351:1100 2:N:0:1
TTACNGAACAATNNTTANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNCCGTTTTGGATTTAACCGAAGATGATTTCGATTTTCTGACGAGTAACAAAGTTTGGATTGCTACTGACCGCTCTCGTGCTCGTCGCTG
+
C@CC#,=CFGFG##,=C##############################################::CFGGGGGGGGGGFFGGGG7FFGGGGGGGGGGGGGGGGGEEGGGGGGGGGGGGGGGGGDGGFGFEFGDEEGGFF6DFCFFGGGGCB+
--
@M01596:22:000000000-A7YH7:1:1101:14066:1102 2:N:0:1
TGGANGCCAAGCNTTGGNGANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNAGAGCCTCGATACGCTCAAAGTCAAAATAATCAGCGTGACATTCAGAAGGGTAATAAGAACGAACCATAAAAAAGCCTCCAAGATTTG
+
A8-@#,=CFFGG#=@DF#=C###########################################::CFFGFGGGFFFGGGGGGGCFGGGGGGGFGGGGGGGGGGG<FFGGGFCGGGGGGGGFGGGEGGGCGGGGGDGGGFGGGGGGGGEFEA
--
@M01596:22:000000000-A7YH7:1:1101:9477:1109 2:N:0:1
GACTCACGACTGCTACCTCANNNNNNNNNNNNNNNNNNNNTNNNNNNNNNNNNNNNNNNNNNGTCCGGGTGCCATATGATTGTTGCAATTGATGTTTTCACCCATTTGTTTTTTTCTCAAAAATATTGATTGCGCGTCAGGTAGGGTAGAA
+
CCCCCGGGGGGGGGGGGGGG####################:#####################::CFGGGEGGGGGGGGFGGGGGGGGGGGGGGGFFGGGGGEGGGGGGGGGGGGGGGGGGGGGFGGGGGGGDGGGGGGEGGGGFGGGGDGF
--


Output:

Code:
@M01596:22:000000000-A7YH7:1:1101:16615:1070 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNCAAGGTATTATAAGCCGTACAGGTGCCGTCGCGTACTCGCGTGAAACTCCTATCCTCTCCTGCTCGGCATTCGAATTCAGGTCGTGCT
@M01596:22:000000000-A7YH7:1:1101:19605:1070 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTTCAGAGTAACACCGGAAAGCGTTACCGCTAATTGTTGAGCACGATGCCAATCACGGCGATGTTCGAATTATTGTTGTGCTCGCTACA
@M01596:22:000000000-A7YH7:1:1101:9956:1070 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGCCGGGCAATAATGTTTATGTTGGTTTCATGGTTTGGTCTAACTTTACCGCTACTAAATGCCGCGGATTGGTTTCGCTGAATCAGGTT
@M01596:22:000000000-A7YH7:1:1101:21195:1071 2:N:0:1
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTCCTCAAGGCGTCAGTATTGTTGAAGTTGTGTCCATCAGGGAGGTGACAATGAATTTCTGCTGTGCTCGCTACAGACTCGGACAGATC
@M01596:22:000000000-A7YH7:1:1101:12710:1082 2:N:0:1
NNNNNCANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTCAAATCCGGCGTCAACCATACCAGCAGAGGAAGCATCAGCACCAGCACGCTCCCAAGCATTAAGCTCAGGAAATGCAGCAGCAAGAT
@M01596:22:000000000-A7YH7:1:1101:21487:1088 2:N:0:1
NNCTNACNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGAGAGGCCGGGGCATTTTCCGCTGCGGTTGGGACGGGAGAGGCCAGGGGCGTGCCATCGAGCACTACTGGAGAAAAATGATCTTTGCT
@M01596:22:000000000-A7YH7:1:1101:11107:1088 2:N:0:1
NNATNATNTNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTCGCTGCGTTGAGGCTTGCGTTTATGGTACGCTGGACTTTGTAGGATACCCTCGCTTTCCTGCTCCTGTTGAGTTTATTGCTGCCGTC
@M01596:22:000000000-A7YH7:1:1101:11149:1092 2:N:0:1
GACTNACGANNNNNANCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNCCACGCTGCGTCACCGAGCTAATCCCAGTATGACACCATTGTTCTTCTACCACATGCATTCTGAATTGTCGATGTGCTCGCTACAGAC
@M01596:22:000000000-A7YH7:1:1101:16931:1092 2:N:0:1
CATGNACTTNNNNNANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTACAGTAGAGTCAATAGCAAGGCCACGACGCAATGGAGAAAGACGGAGAGCGCCAACGGCGTCCATCTCGAAGGAGTCGCCAGCGATA
@M01596:22:000000000-A7YH7:1:1101:10051:1093 2:N:0:1
CTTCNTCCTNNTNNTNTNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTTGCTACTGACCGCTCTCGTGCTCGTCGCTGCGTTGAGGCTTGCGTTTATGGTACGCTGGACTTTGTAGGATACCCTCGCTTTCCTGC
@M01596:22:000000000-A7YH7:1:1101:12072:1097 2:N:0:1
GACTNACGACTGNNANCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGTTGTGCTCGCTACAGACTCGGACAGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGTATCATTAAAAAA
@M01596:22:000000000-A7YH7:1:1101:21840:1098 2:N:0:1
GACTNACGACTGNNANCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTATAGAATTGTTACTGTGCTCGCTACAGACTCGGACAGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGT
@M01596:22:000000000-A7YH7:1:1101:14351:1100 2:N:0:1
TTACNGAACAATNNTTANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNCCGTTTTGGATTTAACCGAAGATGATTTCGATTTTCTGACGAGTAACAAAGTTTGGATTGCTACTGACCGCTCTCGTGCTCGTCGCTG
@M01596:22:000000000-A7YH7:1:1101:14066:1102 2:N:0:1
TGGANGCCAAGCNTTGGNGANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNAGAGCCTCGATACGCTCAAAGTCAAAATAATCAGCGTGACATTCAGAAGGGTAATAAGAACGAACCATAAAAAAGCCTCCAAGATTTG
@M01596:22:000000000-A7YH7:1:1101:9477:1109 2:N:0:1
GACTCACGACTGCTACCTCANNNNNNNNNNNNNNNNNNNNTNNNNNNNNNNNNNNNNNNNNNGTCCGGGTGCCATATGATTGTTGCAATTGATGTTTTCACCCATTTGTTTTTTTCTCAAAAATATTGATTGCGCGTCAGGTAGGGTAGAA

I want to print line starting with "@M" and its following line.

Thanks all.

Last edited by huiyee1; 03-12-2014 at 05:49 AM..
# 2  
Old 03-12-2014
Code:
sed -n "/^@M/{N;p;}" file

Or

Code:
awk ' /^@M/ { getline a; print $0 "\n" a } ' file

This User Gave Thanks to anbu23 For This Post:
# 3  
Old 03-12-2014
With grep:
Code:
grep -A1 --no-group-separator '^@M' file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

Delete all lines except a line starting with string

Shell : bash OS : RHEL 6.8 I have a file like below. $ cat pattern.txt hello txt1 txt2 txt3 some other text txt4 I want to remove all lines in this file except the ones starting with txt . How can I do this ? (4 Replies)
Discussion started by: omega3
4 Replies

3. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

4. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

5. Shell Programming and Scripting

Reformatting single column text file starting new line when finding particular string

Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address. I want to turn this 172.xx.xx.xx gwpusprdrp02_pv seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies

6. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

7. Shell Programming and Scripting

Using awk to print line starting with particular word

Hi Geeks, Consider this line: driver=c:\folder1\folder2 The above line is contained in a variable say 'var' . I want to copy everything after 'driver=' in to another variable say var2. Please tell me how can this be done. (8 Replies)
Discussion started by: ajincoep
8 Replies

8. Shell Programming and Scripting

Print starting 3rd line until end of the file.

Hi, I want to Print starting 3rd line until end of the file. Pls let me know the command. Thanks in advance. (1 Reply)
Discussion started by: smc3
1 Replies

9. Shell Programming and Scripting

how to delete text from line starting pattern1 up to line before pattern2?

My data is xml'ish (here is an excerpt) :- <bag name="mybag1" version="1.0"/> <contents id="coins"/> <bag name="mybag2" version="1.1"/> <contents id="clothes"/> <contents id="shoes"/> <bag name="mybag3" version="1.6"/> I want to delete line containing mybag2 and its subsequent... (5 Replies)
Discussion started by: repudi8or
5 Replies
Login or Register to Ask a Question