Help with selecting specific lines in a large file

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with selecting specific lines in a large file
# 1  
Old 02-05-2008
Help with selecting specific lines in a large file


I need to select the 3 lines above as well as below a search string, including the search string.

I have been trying various combinations using sed command without any success.

Can anuone help please.

# 2  
Old 02-05-2008
If you can use grep instead of sed the grep options -A -B or -C should allow you to do what you want to do.
# 3  
Old 02-06-2008
Hello, Thanks for the reply.

But I don't think I can use grep as I don't know what are the data block in between teh search string.
My file layout is as follows:

(numerous lines)
(numerous lines)
(numerous lines)
(numerous lines)

And so on. I only need to get the 3 lines above and below the -----------
as well as the -------------

Thanks for any assistance

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash : Checking Large file for specific lines

Morning .. I have a file with approximately 1000 lines. I want to check that the file contains, for example, 100 lines. Something like whats given below is ugly. And even if I create a function I have to call it 100 times. I may need to look through multiple files at times. Is there a... (4 Replies)
Discussion started by: sumguy
4 Replies

2. UNIX for Beginners Questions & Answers

Selecting specific variable in log file

Hi there I am trying to look for a specific word in the log file and I am aware this can be done by grep for example. As there will be multiple entries for this I want to grep the last one to enter the log... how would I go about this - would I have to use tail? Thanks in advance Alex (4 Replies)
Discussion started by: simpsa27
4 Replies

3. Shell Programming and Scripting

Help with awk for selecting lines in a file avoiding repetition

Hello, I am using Awk in UBUNTU 12.04. I have a file as following with 48,432,354 lines and 4 fields. The file has this structure (There are repetitions of the first column in several lines) AB_14 S54 A G AB_14 S55 A A AB_14 S56 G G GO_15 S45 T A GO_15 S46 A A PT_16 S33 C C PT_16 ... (4 Replies)
Discussion started by: Homa
4 Replies

4. Shell Programming and Scripting

selecting and deleting specific lines with condition

I have a set of data as below: The first field, $1 represent "|". The $3 (3rd field) and $6 (6th field) in my data file represent "number-molecule" which has arrangement as below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... (9 Replies)
Discussion started by: vjramana
9 Replies

5. Shell Programming and Scripting

selecting specific fields in a file (maybe with sed?)

Hi, I have a file with following lines: chr1 10 AC=2;AF=1.00;AN=2;DP=2;Dels=0.00;HRun=0;HaplotypeScore=0.00;MQ=23.00;MQ0=0;QD=14.33;SB=-10.01 chrX 18 AB=0.52;AC=1;AF=0.50;AN=2;DP=203;DS;Dels=0.00;HRun=0;HaplotypeScore=20.01;MQ=15.63;MQ0=85;QD=12.80;SB=-1289.58 I need to extract 4... (2 Replies)
Discussion started by: menenuh
2 Replies

6. Shell Programming and Scripting

Selecting specific 'id's from lines and columns using 'SED' or 'AWK'

Hello experts, I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Discussion started by: kamskamu
6 Replies

7. Shell Programming and Scripting

Selecting lines of a file

Say I wanted to select the 5th line of a file without knowing the context of the file. Would I use grep and pipe it into wc or is there a more simple way of doing this? (3 Replies)
Discussion started by: puttster
3 Replies

8. Shell Programming and Scripting

Selecting Lines on text file

Hi All, I am creating a script that sends log data from text files to a Database and I will like to read sugestions, as I think that there might be better ways to achive this than with my shell script; maybe perl or I don't know, but I will like to read some sugestions. The log is from... (10 Replies)
Discussion started by: oconmx
10 Replies

9. UNIX for Dummies Questions & Answers

command for selecting specific lines from a script

I need help on following script: I need to print the lines which are in bold letters in separate file as record string("|") emp_name; string("|") emp_id; decimal("|") emp_salary; string("|") emp_status; string("\n") emp_proj; end (1 Reply)
Discussion started by: gardasgangadhar
1 Replies

10. Shell Programming and Scripting

Urgent: selecting unique specific content of a file using shell script

Hi, I have a file whose content and format at places is as given below. print coloumn .... coloumn .... coloumn .... skip 1 line print coloumn ... skip 1 line I need to select the following : print coloumn .... coloumn .... coloumn... (2 Replies)
Discussion started by: jisha
2 Replies
Login or Register to Ask a Question