If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Deleting lines from line 40 to end of the file using korn shell

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-04, 17:24
kyennara kyennara is offline
Registered User
 
Join Date: Jul 2004
Posts: 1
Arrow Deleting lines from line 40 to end of the file using korn shell

Hi,

I 'm new to shell script and seems like you answered lot of questions in shell, Please help me to answer this question,

I have a file called temp1.txt, data in this file is

abcd text1 text2 sdksjdj
ands text2 text isudiusd
DELETE D D SDSDS
DELETE D D DFSSDSD

I would like to delete everything after DELETE and put it in a file, everything before DELETE I would like to put it in another file, basically I want to split the data in to two files, is there a way to do this in korn shell?

Please help.
Thanks.
Kondal
Reply With Quote
  #2 (permalink)  
Old 07-23-04, 17:45
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
This is to put all the lines that start with 'DELETE" in one file (with '.del' suffix) and all the others in the other (with the '.nor).

Save the attached code as 'ky.awk' file and:

nawk -f ky.awk temp1.txt

Code:
BEGIN {
   SUF_delete=".del"
   SUF_normal=".nor"
}
/^DELETE/ { print >> (FILENAME SUF_delete) ; next}
{ print >> (FILENAME SUF_normal) }
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On