need help cutting consecutive lines with sed or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help cutting consecutive lines with sed or awk
# 1  
Old 06-04-2008
need help cutting consecutive lines with sed or awk

HI All,

I want to cut 5 lines after a pattern using sed or awk. can any one tell me how to do it ?
# 2  
Old 06-04-2008
Code:
$ cat file.txt
AA
BB
CC
DD
EE
FF
GG
HH
II
$ sed -n '/^DD/{p;n;p;n;p;n;p;n;p;}' file.txt
DD
EE
FF
GG
HH

or 

If you don't want the pattern,
$ sed -n '/^DD/{n;p;n;p;n;p;n;p;n;p;}' file.txt

//Jadu
# 3  
Old 06-04-2008
Code:
awk '/pattern/{n=5;next}n{print;n--}' file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

find pattern matches in consecutive lines in certain fields-awk

I have a text file with many thousands of lines, a small sample of which looks like this: InputFile:PS002,003 D -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0 PS002,003 PSQ 0 1 7 18 1 0 -1 1 1 3 -1 -1 ... (5 Replies)
Discussion started by: jvoot
5 Replies

2. UNIX for Beginners Questions & Answers

awk - If field value of consecutive records are the identical print portion of lines

I have some data that looks like this: PXD= ZW< 1,6 QR> QRJ== 1,2(5) QR> QRJ== 4,1(2) QR> QRJ== 4,2 QRB= QRB 4,2 QWM QWM 6,2 R<C ZW< 11,2 R<H= R<J= 6,1 R>H XZJ= 1,2(2) R>H XZJ= 2,6(2) R>H XZJ= 4,1(2) R>H XZJ= 6,2 RDP RDP 1,2 What I would like to do is if fields $1 and $2 are... (5 Replies)
Discussion started by: jvoot
5 Replies

3. Shell Programming and Scripting

awk print values between consecutive lines

I have a file in below format: file01.txt TERM TERM TERM ABC 12315 68.53 12042013 165144 ABC 12315 62.12 12042013 165145 ABC 12315 122.36 12052013 165146 ABC 12315 582.18 12052013 165147 ABC 12316 2.36 12052013 165141 ABC 12316 ... (8 Replies)
Discussion started by: alex2005
8 Replies

4. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

5. Shell Programming and Scripting

Grep couple of consecutive lines if each lines contains certain string

Hello, I want to extract from a file like : 20120530025502914 | REQUEST | whatever 20120530025502968 | RESPONSE | whatever 20120530025502985 | RESPONSE | whatever 20120530025502996 | REQUEST | whatever 20120530025503013 | REQUEST | whatever 20120530025503045 | RESPONSE | whatever I want... (14 Replies)
Discussion started by: black_fender
14 Replies

6. Shell Programming and Scripting

How to compare the values of a column in awk in a same file and consecutive lines..

I would like to compare the values of 2nd column of consecutive lines of same file in such a way so that if the difference between first value and second value is more than 100 it should print complete line else ignore line. Input File ========== PDB 2500 RTDB 123 RTDB-EAGLE 122 VSCCP 2565... (4 Replies)
Discussion started by: manuswami
4 Replies

7. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

8. Shell Programming and Scripting

Script in SED and AWK so that it treats consecutive delimiters as one

Hi All, I am trying to cut to do a cut operation, but since there are seems to be more than one deltimiters in some occasion I am not able to get the exact field. Can you please provide an SED and AWK script for treating the source file in such a way that all consecutive delimiters are treated... (3 Replies)
Discussion started by: rakesh.su30
3 Replies

9. UNIX for Dummies Questions & Answers

Cutting n consecutive lines from a file...

Hi, I have this problem of separating 10 consecutive lines from a file, say starting from 21 to 30... I have used a filter like this.. head -n 30 myfile | tail -n 10 Is there a simpler way than this? (2 Replies)
Discussion started by: Vishnu
2 Replies

10. UNIX for Dummies Questions & Answers

Cutting lines out using sed I presume.

Happy New Year!!! I'm trying to cut out some text in a data file where I only want the first line and the last line. For example. 1. Colin Was here <<-- Text I want to cut out 2. THIS IS THE TEXT I WANT TO CUT <- CUT THIS OUT 3. OUT BECAUSE IT'S NO GOOD TO ME <- CUT THIS OUT 4. I... (5 Replies)
Discussion started by: cfoxwell
5 Replies
Login or Register to Ask a Question