Extracting the lines between 2 strings of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting the lines between 2 strings of a file
# 1  
Old 02-14-2007
Extracting the lines between 2 strings of a file

Hi,

I have a sql file and i need to extract the table names used in the sql file using a unix script. If i can extract the lines between the keywords 'FROM' and 'WHERE' in the file, my job is done. can somebody tell me how to do this using a shell script. If u can just let me know, how to extract the lines between 2 strings, it would be a great help.
Thanks in advance.
# 2  
Old 02-14-2007
Code:
sed -n "/FROM/,/WHERE/p" file

# 3  
Old 02-14-2007
Another way :
Code:
awk '/FROM/,/WHERE/' file


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting strings at various positions of text file

Hi Team - I hope everyone has been well! I export a file from one of our source systems that gives me more information than I need. The way the file outputs, I need to extract certain strings at different positions on the file and echo them to another file. I can do this in batch easily,... (2 Replies)
Discussion started by: SIMMS7400
2 Replies

2. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

3. Shell Programming and Scripting

Extracting strings from a log file.

I'm new to all this and I've been fiddling with this problem for HOURS and feel silly that I can't work it out! I have a .log file that VERY long and looks like this: 2011-08-31 10:03:34 SUESTART AG Amndmnt Client WebRequest DNU SUEEND Sequence: 600, 2011-08-31 10:03:34 SUESTART... (11 Replies)
Discussion started by: SusieSA
11 Replies

4. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

5. UNIX for Advanced & Expert Users

Extracting Lines in a file

Hi, We have a file where we need to extract the lines of a file based on the first three characters of every line in that file. Eg: RAM hill station SAM student RAM rose SAM apple RAM india SAM australia RAM happy RAM heaven SAM smile RAM glow So, all the lines that start... (5 Replies)
Discussion started by: pyaranoid
5 Replies

6. UNIX for Dummies Questions & Answers

extracting lines from a file

i want to extract lines 5 and 7 from a txt file which contains nearly 20 entries how to do it also i want to check whether the 42nd character is 'S' in that line suggestions welcome (4 Replies)
Discussion started by: trichyselva
4 Replies

7. Shell Programming and Scripting

Extracting lines between 2 strings only if the pattern patches

Hi Friends, Please help me with the following problem: I have an xml file with the following lines: <init-param> <param-name>/default/directory</param-name> <param-value>default</param-value> </init-param> <init-param> ... (5 Replies)
Discussion started by: simran
5 Replies

8. Shell Programming and Scripting

extracting a set of strings from a text file

i have textfiles that contain a series of lines that look like this: string0 .................................................... column3a column4a string1**384y0439 ..................................... column3b column4b... (2 Replies)
Discussion started by: Deanne
2 Replies

9. Shell Programming and Scripting

Help with extracting strings from a file

I want to collect the characters from 1-10 and 20-30 from each line of the file and take them in a file in the following format.Can someone help me with this : string1,string2 string1,string2 string1,string2 : : : : (7 Replies)
Discussion started by: cmsdelhi
7 Replies

10. Shell Programming and Scripting

extracting lines from a file

Hi all, I need to extract some lines from a file based on a condition. For ex: My file will contain 50 lines and i need to extract line which has "File" in it and then the line which has "date" in it. Which command will be the most efficient way to do it. I have tried two ways 1.... (1 Reply)
Discussion started by: pradeepthanraj
1 Replies
Login or Register to Ask a Question