Partial Delete Lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Partial Delete Lines
# 1  
Old 05-13-2010
Partial Delete Lines

Hi,
Need to delete line prior to (INSERT/UPDATE/DELETE). In case ' available, then keep that. Pls refet below details.

Input
======================
Code:
l_s := '             INSERT INTO TEST'
l_P PD := '         UPDATE INTO TEST'
l_D := ' DELETE INTO TEST'
This is test

Output
======================
Code:
'INSERT INTO TEST'
'UPDATE INTO TEST'
'DELETE INTO TEST'
This is test


Last edited by vgersh99; 05-13-2010 at 01:39 PM.. Reason: code tags, PLEASE!
# 2  
Old 05-13-2010
This do for your needs ?

Code:
#  sed "s/[^']*'/'/" infile
' INSERT INTO TEST'
' UPDATE INTO TEST'
' DELETE INTO TEST'
This is test

# 3  
Old 05-14-2010
Above solution is not working. Tried below statement, however nothing is happening.

echo "l_s := ' INSERT INTO TEST'"|sed "s/[^']*'/'/"

Expected Output
Code:
'INSERT INTO TEST'

Actual Output
Code:
'             INSERT INTO TEST'


Last edited by Scott; 05-14-2010 at 03:49 AM.. Reason: Code tags, please...
# 4  
Old 05-14-2010
Quote:
Originally Posted by saurabhbaisakhi
Above solution is not working. Tried below statement, however nothing is happening.

Code:
echo "l_s := '             INSERT INTO TEST'"|sed "s/[^']*'/'/;s/' */'/"

Expected Output
=====
Code:
'INSERT INTO TEST'

Actual Output
=====
Code:
'             INSERT INTO TEST'

Simply add the red marked part to the sed command, which will improve Tytalus' approach.
Besides I added your commands in code tags.

Code:
$ cat file
'             INSERT INTO TEST'
'         UPDATE INTO TEST'
' DELETE INTO TEST'
This is test
$ sed "s/[^']*'/'/;s/' */'/" file
'INSERT INTO TEST'
'UPDATE INTO TEST'
'DELETE INTO TEST'
This is test
$

# 5  
Old 05-14-2010
All, appreciate your beautiful reply and it's making me sense to move forward, however I am stcuk and unable to finalize the command. Pls refer the details below.

Pls note that, deletion needs to be done, only after having INSERT/UPDATE/DELETE statement in the line.

Input
Code:
l_s := '    INSERT INTO FIRST
THIS IS 'SECOND
L_P :='     UPDATE ON THIRD
l_t := '    DELETE ON FORRTH
'   INSERTING INTO FIFTH'

Output
Code:
'INSERT INTO FIRST
THIS IS 'SECOND
'UPDATE ON THIRD
'DELETE ON FORRTH
'   INSERTING INTO FIFTH'


Last edited by Scott; 05-14-2010 at 03:49 AM.. Reason: Final warning to use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to compare partial filenames in two folders and delete duplicates

Background: I use a TV tuner card to capture OTA video files (.mpeg) and then my Plex Media Server automatically optimizes the files (transcodes for better playback) and places them in a new directory. I have another Plex Library pointing to the new location for the optimized .mp4 files. This... (2 Replies)
Discussion started by: shaky
2 Replies

2. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

3. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

4. UNIX for Advanced & Expert Users

Grep returning partial lines due to special characters

Hey guys, I have a file with an ID which I'm using to grep out the original record from another file. Problem is I have special characters in the original file, and grep is returning only a partial record. How can I get around this? Appreciate your help! Pete (3 Replies)
Discussion started by: peteroc
3 Replies

5. UNIX for Advanced & Expert Users

In a huge file, Delete duplicate lines leaving unique lines

Hi All, I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space. I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Discussion started by: krishnix
16 Replies

6. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

7. UNIX for Dummies Questions & Answers

How to delete partial duplicate lines unix

hi :) I need to delete partial duplicate lines I have this in a file sihp8027,/opt/cf20,1980182 sihp8027,/opt/oracle/10gRelIIcd,155200016 sihp8027,/opt/oracle/10gRelIIcd,155200176 sihp8027,/var/opt/ERP,10376312 and need to leave it like this: sihp8027,/opt/cf20,1980182... (2 Replies)
Discussion started by: C|KiLLeR|S
2 Replies

8. Shell Programming and Scripting

How to delete lines in a file that have duplicates or derive the lines that aper once

Input: a b b c d d I need: a c I know how to get this (the lines that have duplicates) : b d sort file | uniq -d But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem. (3 Replies)
Discussion started by: necroman08
3 Replies

9. Shell Programming and Scripting

shell script to partial delete

guys i need some help in writing a shell script, what i am trying to write is a shell script that can delete generated trace files my software usually generated everyday, i will give an example to make it easy to understand root@cms-db # pwd /pcard17/trace root@cms-db # ls -l HSM_VERIF.TRC*... (4 Replies)
Discussion started by: q8devilish
4 Replies

10. UNIX for Advanced & Expert Users

delete line from file if successful partial string found

Id like to delete a line from a file using (preferably a single line unix command) if it contains a certain string pattern. If line contains "abcdef" then delete that line. Help greatly appreciated. (7 Replies)
Discussion started by: cronjob78
7 Replies
Login or Register to Ask a Question