![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| deleting lines by number | cary530 | UNIX for Dummies Questions & Answers | 9 | 03-30-2009 02:09 PM |
| deleting lines using awk-best way? | satnamx | Shell Programming and Scripting | 3 | 08-29-2007 07:24 PM |
| Deleting lines in a file | reachsamir | Shell Programming and Scripting | 2 | 05-29-2007 11:17 AM |
| Deleting last 2 lines from the file. | videsh77 | Shell Programming and Scripting | 4 | 04-06-2007 01:14 PM |
| deleting lines | supercbw | High Level Programming | 1 | 05-06-2002 12:53 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
deleting lines
I am trying deleting lines from a text file using sed..
sed '/OBJECT="ABC/{N;N;N;d; }' will do if i have to delete lines starting with Object and next 3 lines but I was looking for a way to delet lines starting with OBJECT and all the lines till it reaches a blank lines ..or it reaches a line with OBJECT in it ... i tried all kind of things .. didn't work . Will appreciate help thanks in advance .. ![]() |
|
||||
|
deleting lines following pattern
this script deletes line with pattern and again search for pattern and deletes it ..
May be i haven't explained properly... Once i delete the line with pattern i need to delete all the lines after the pattern till the time it sees a blank line. I am working on database file .. which is in this format .. OBJECT="NAME" ACTION="REDEFINE" "NAME_A"="KAJNABI-XYZ" DESCRIPTION="FGH" . . . . AUTO_RESET="0" . . . ***************BLANK LINE********** OBJECT="NAME" ACTION="REDEFINE" "NAME_A"="AJNABI-GFT" DESCRIPTION="GFR" . . . . AUTO_RESET="0" . . . OBJECT="NAME" ACTION="REDEFINE" "NAME_A"="KAJNABI-XYZ" DESCRIPTION="FGH" . . . . AUTO_RESET="0" . . . WHAT i need to do is delete line with pattern say KAJNABI and delete all the lines after it till it sees the blank line .. and again search for the pattern and does the same again ... I understand that i will have to use the loop but how exactly I am going to do this .. makes me confused .... thanks |
|
|||||
|
I understand the script in general now..
From what I see, the part where n deletes the next line should delete all lines until the next $target is found, but it doesn't; however, the second instance of s/${target}// should actually be searching for a blank line instead of $target.. |
|
||||
|
code:--------------------------------------------------------------------------------#! /usr/bin/ksh
target=OBJECT sed -n -e " s/${target}// t loop p b :loop s/.*// n s/^$// # till the blank line t b loop" exit 0 did the job ... Thanks perderabo ... but for some reason i was running script the way it was .. was just deleting one line containing the pattern...Just curious why it ws doing that .. i was trying running this script on database file .. its in the format the way i mentioned in my post...and say my pattern is KAJNABI ... This is the best forum i have seen .... Thanks guys |
![]() |
| Bookmarks |
| Tags |
| sed delete line |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|