Get multiple line content between two chars


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get multiple line content between two chars
# 1  
Old 04-11-2008
Get multiple line content between two chars

Hello -

I have a file that has the something like the following :

REM CREATE TABLE lots of text
REM table specifc creation text ;
REM ALTER TABLE lots of text
REM text specific to the the alter command
REM could be more lines of text;

What I need is to get all the lines for the ALTER TABLE statement up to the ending ; into a seperate file. There are multiple statements within the file and some could be one line some could span more than one line but they all end in a ;

Thanks in advance for your help.
Feliz
# 2  
Old 04-11-2008
Code:
sed -n '/ALTER TABLE/,/;/p' file

You're not saying you want to remove the REMs at the beginning of line, so I didn't do that. If you want it after all, try something like

Code:
sed -n -e '/ALTER TABLE/,/;/{' -e 's/^REM //p' -e } file

# 3  
Old 04-11-2008
Thank you. I also found that this did the trick for me.

awk '/ALTER/,/;/' zpdm1_tab.sql > zpdm1_con.sql

Thanks for your reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break line content into multiple lines using delimiter

I need to break the line after every 3rd semi colon(;) using Unix shell scripting Input.txt ABC;DEF;JHY;LKU;QWE;BVF;RGHY; Output.txt ABC;DEF;JHY; LKU;QWE;BVF; RGHY; (1 Reply)
Discussion started by: meet_calramz
1 Replies

2. Shell Programming and Scripting

Rename and add chars to multiple files at once

i have a little over 100 files named page1.jpg through page106.jpg. How can I rename them all to remove the page word and add 00 in front of the remaining numbers? I realize this might be multiple commands but cp page*.jpg *.jpg didn't work like I thought it would. (4 Replies)
Discussion started by: zimmerru
4 Replies

3. UNIX for Dummies Questions & Answers

Grep with special chars line by line

I have a file that includes strings with special characters, eg file1 line: 1 - special 1 line: = 4 line; -3 etc How can I grep the lines of file1 from file2, line by line? I used fgrep and egrep to grep a particular line and worked fine, but when I used: cat file1|while read line;do... (2 Replies)
Discussion started by: FelipeAd
2 Replies

4. UNIX for Dummies Questions & Answers

Replacing multiple special chars with single char

Hi I've a string . And i need to replace set of characters with a single character Means .. or . or ... and so on should be replaced with single % character Irrespective of number of dots in between the characters , those should be replaced with single % All the above strings should be... (3 Replies)
Discussion started by: smile689
3 Replies

5. Shell Programming and Scripting

Copying lines from multiple logfiles, based on content of the line

d df d d (1 Reply)
Discussion started by: larsk
1 Replies

6. Shell Programming and Scripting

renaming multiple files with first line of content

Hi , I want to rename multiple files with their first line bar the first character + the extension .qual. For the example below the filename should read 7180000000987.qual. I have trawled through different threads for 2 days and I don't seem to find anything I can adopt for this task :confused: ... (7 Replies)
Discussion started by: Bruno
7 Replies

7. Shell Programming and Scripting

removing non-printable chars from multiple files

How do I remove non-printable characters from all txt files and output the results to one file? I've tried the following: tr -cd '\n' < *.txt > out.txt and it gives ambiguous redirect error. How can I get it to operate on all txt files in the current directory and append the output to... (1 Reply)
Discussion started by: revax
1 Replies

8. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies
Login or Register to Ask a Question