Login or Register to Ask a Question and Join Our Community


Grep multiple lines from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep multiple lines from a file
# 1  
Old 06-23-2009
Grep multiple lines from a file

Hi,

I would like to ask if there is any method to grep a chuck of lines based on the latest file in a directory.

E.g

Latest file in the directory:
Line 1: 532243
Line 2: 123456
Line 3: 334566
Line 4: 44567545

I wanted to grep all the line after line 2 i.e. Line 3 and line 4 and then writing them in a file.

Cheers
# 2  
Old 06-23-2009
is your pattern is fixed??
I mean pattern is always 123456??
or you want to print only line 3 and 4 from all files??
# 3  
Old 06-23-2009
@dwgi32: from grep, you mean to say the output of lines itself?

you want the output of the latest file from third line onwards in a new file?
# 4  
Old 06-23-2009
Quote:
Originally Posted by vidyadhar85
is your pattern is fixed??
I mean pattern is always 123456??
or you want to print only line 3 and 4 from all files??
Yes, the pattern is fixed

---------- Post updated at 07:04 PM ---------- Previous update was at 07:02 PM ----------

Quote:
Originally Posted by anchal_khare
@dwgi32: from grep, you mean to say the output of lines itself?

you want the output of the latest file from third line onwards in a new file?
Yes. > a.txt
# 5  
Old 06-23-2009
Code:
awk '/Line 2/{f=1;next};f' file

# 6  
Old 06-23-2009
Code:
tail +3 <latest-file> | grep 123456 > new_file.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

3. UNIX for Dummies Questions & Answers

Grep multiple lines

I want to grep multiple lines from a text file. I want to grep all lines containing X,Y and NA in a single command. How do I go about doing that? This is what my text files look like: rs1983866 0.0983 10 100016313 rs1983865 0.5994 X 100016339 rs1983864 0.3272 11 100017453 rs7077266... (2 Replies)
Discussion started by: evelibertine
2 Replies

4. UNIX for Advanced & Expert Users

grep across multiple lines

How do you grep 'select * from table_name' string from a script if the select * and from table_name are on 2 different lines ? like select * from table_name Any help would be greatly appreciated !!! Thanks RDR (4 Replies)
Discussion started by: RDR
4 Replies

5. UNIX for Dummies Questions & Answers

grep in multiple lines

hi i have kind of below text in a file. I want to get a complete paragraph starting with START and ending with before another START) which has a particular string say XYZ or ABC START XYZ hshjghkjh 45 ljkfd fldjlj d jldf START 3493u ABC 454 4545454 4545454 45454 4545454 START ...... (3 Replies)
Discussion started by: reldb
3 Replies

6. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

7. Shell Programming and Scripting

Grep multiple lines and save to a file

Sir I have a data file e.g. DATA31082009. This file consists of several data files appended to that file. The size of each data file is different. The first line of each file starts with "44". I want to grep data from "44" to the preceding line of next "44" and save it as a individual file.... (10 Replies)
Discussion started by: chssastry
10 Replies

8. AIX

Grep multiple lines and redirect to file

I have setof files with data and with same fields multiple times in each of the files. for example: file 1 name = mary kate last name = kate address = 123 street = abc name = mary mark last name = mark address = 456 street = bcd file 2 name = mary kate last name = kate... (2 Replies)
Discussion started by: relearner
2 Replies

9. Shell Programming and Scripting

grep multiple lines

Hi. I have this format on a textfile: VG Name /dev/vg00 PV Name /dev/dsk/c16t0d0 PV Name /dev/dsk/c18t0d0 PV Name /dev/dsk/c16t4d0 VG Name /dev/vg01 PV Name ... (6 Replies)
Discussion started by: jOOc
6 Replies

10. Shell Programming and Scripting

Grep on multiple lines

I 'm trying to grep 2 fieldds on 2 differnt lines. Like this: psit > file egrep -e '(NS|ES)' $file. Not working. If this succeeds then run next cmd else exit. Pls Help Gundu (13 Replies)
Discussion started by: gundu
13 Replies
Login or Register to Ask a Question

Featured Tech Videos