How do delete certain lines alone which are matching with start and end string values in file?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How do delete certain lines alone which are matching with start and end string values in file?
# 1  
Old 10-21-2019
How do delete certain lines alone which are matching with start and end string values in file?

Hi, In my previous post ( How to print lines from a files with specific start and end patterns and pick only the last lines? ), i have got a help to get the last select statement from a file, now i need to remove/exclude the output from main file:

Code:
Input File format:
SELECT  
ABCD,
DEFGH,
DFGHJ,
JKLMN,
AXCVB,
DFVBNM,
QWER,
RTU,
TYUI,
IOPL from test1
limit 1;

delete from test2;

SELECT  ABCD,
DEFGH,
DFGHJ,
JKLMN,
AXCVB,
DFVBNM,
QWER,
RTU,
TYUI,
IOPL from test1
limit 1;

create table as SELECT  
ABCD,
DEFGH,
DFGHJ,
JKLMN,
AXCVB,
DFVBNM,
QWER,
RTU,
TYUI,
IOPL from test1
limit 1;

SELECT  ABCD,
DEFGH,
DFGHJ,
JKLMN,
AXCVB,
DFVBNM,
QWER,
RTU,
TYUI,
IOPL from test1
limit 1;


SELECT 
ABCD,
DEFGH,
DFGHJ,
JKLMN,
AXCVB,
DFVBNM,
QWER,
RTU,
TYUI,
IOPL from test1
limit 1;

SELECT  
ABCD,
DEFGH,
from test1
limit 1;

delete from test2;

create table as SELECT  
ABCD,
DEFGH,
DFGHJ,
JKLMN,
AXCVB,
DFVBNM,
QWER,
RTU,
TYUI,
IOPL from test1345
limit 1;

create table as SELECT  ABCD,
DEFGH,
DFGHJ,
JKLMN,
AXCVB,
DFVBNM,
QWER,
RTU,
TYUI,
IOPL from test123
limit 1;



Code:
Input Format 2 ( which is the output of command ) awk '$1=="SELECT"{s=$0} END{if(s) print s}' RS= file


SELECT  
ABCD,
DEFGH,
from test1
limit 1;

OUTPUT Format should be INPUT Format - Input Format 2 ( only input format exact lines from 'select' to ';' should be removed from Input format.
# 2  
Old 10-21-2019
Hi,

The UNIX and Linux Forums are a tech site to help you administrator your computer(s) and to help you write your own scripts. We are not here to write your scripts for you.

Please post your work, the scripts you have written, any error messages you saw, etc.

Thanks.
# 3  
Old 10-22-2019
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

Delete all lines from file matching a string

I wish to search and delete all lines in /app/Jenkins/deploy.txt having this filename string /app/Jenkins/file2.mrt as entry: I'm using : colon as delimiter in sed command as I'm dealing with file paths. Below is the command I was expecting to work. sed -i ":/app/Jenkins/file2.mrt:d"... (1 Reply)
Discussion started by: mohtashims
1 Replies

3. Shell Programming and Scripting

Search a String between start and end of a block in a file

Hi, I have a scenario where I want to display the output based on the pattern search between the start and end of a block in a file, we can have multiple start and end blocks in a file. Example give below, we need to search between the start block abc and end block def in a file, after that... (5 Replies)
Discussion started by: G.K.K
5 Replies

4. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

5. Shell Programming and Scripting

Generate Codes based on start and End values of numbers in a column

Hello All, Could you please help with this. This is what I have: 506234.222 2 506234.222 2 506234.222 2 506234.222 2 508212.200 2 508212.200 2 333456.111 2 333456.111 2 333456.111 2 333456.111 2 But this is what I want: 506234.222 1 506234.222 2 506234.222 2 506234.222 3 (5 Replies)
Discussion started by: canimba
5 Replies

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. Shell Programming and Scripting

print string at the end of lines in text file

hello, I go text file like this E:/DDD/Dyndede/wwww E:/DDD/sss.com/ffffg/fff E:/DDD/vvvvvv/dd E:/DDD/sss.com/bbbbbb E:/DDD/sss.com/nnnn/xxI want to print /alpha.jpg at the end of every lines like that E:/DDD/Dyndede/wwww/alpha.jpg E:/DDD/sss.com/ffffg/fff/alpha.jpg... (8 Replies)
Discussion started by: davidkhan
8 Replies

8. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

9. Shell Programming and Scripting

delete lines in file matching a pattern

I have a text file, a sample of which is as follows: r/- * 0: WINDOWS/Microsoft.NET/Framework/v2.0.50727/ASP.NETWebAdminFiles/Images/headerGRADIENT_Tall.gif r/- * 0: WINDOWS/SoftwareDistribution/Download/cf8ec753e88561d2ddb53e183dc05c3e/backoff.jpg r/- * 0: ... (2 Replies)
Discussion started by: stumpyuk
2 Replies

10. Shell Programming and Scripting

Delete blank lines at the end of file

I am attempting to delete blank lines in my file and I've used this command: sed '/^$/d' $file > $file.fixed all this seems to do is copy the file and not delete the blank lines located at the end of the file. Any assistance would be greatly appreciated. (3 Replies)
Discussion started by: TL56
3 Replies
Login or Register to Ask a Question