The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
how to read record by record from a file in unix raoscb UNIX for Dummies Questions & Answers 1 05-16-2008 06:30 AM
Remove First and Last Record from a file ravikuc UNIX for Dummies Questions & Answers 1 10-11-2007 03:35 AM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 01:58 PM
command to remove last record on file mheinen UNIX for Dummies Questions & Answers 4 01-09-2007 03:39 PM
remove duplicated xml record in a file under unix happyv Shell Programming and Scripting 8 09-20-2006 01:36 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-22-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
How to remove a particular record from a file?

Please tell me the command(s) to remove a particular record from the file and placing the rest of the record in a seperate file.
Sponsored Links
  #2 (permalink)  
Old 07-22-2008
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 901
Post a sample of your input file in the original format and the exact output you want and please place them within code tags (select the text and click on the # symbol above the edit window).
  #3 (permalink)  
Old 07-22-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
Please find the attached file in text format.

say if i have to remove the NA2 record and NPD record. (this is a portion of file which contains thousands of records). i believe sed pattern matching will work.
Attached Files
File Type: txt file.txt (1.2 KB, 25 views)
  #4 (permalink)  
Old 07-22-2008
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 901
grep solution
Code:
grep -v '^NA2\|^NPD' file > new_file
  #5 (permalink)  
Old 07-22-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
file type:

Code:
NMT000010000100001ENVL,CSP,28#,9X12,KFT,1C                                                        00001
NA20000105500000003081547100100008000000000024.19         000000000000001DZ  000000000024.19  000000000000000  00002
NPD                                                                                                                                            TOP63120                      TOP63120
NP2                                                                                                                                                                                                                                                                                                                                                                                             00000000000000 00000000000000                                                             000                                                                                                                                                                           00000000000000                               00000000000001 00000000000000                                               00000000000000
NMT000010000800001PAD,LGL RL,PRISM,LTR,BE
  #6 (permalink)  
Old 07-22-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
grep is not doing anything.
new_file is still with the same records.
anything with the sed?
  #7 (permalink)  
Old 07-22-2008
Registered User
 

Join Date: Jul 2008
Location: BlackMesh Managed Hosting
Posts: 66
Code:
grep -vE '^(NPD|NA2)' file > file2
While it's trivial to do this in sed, if there's a way to remove newlines in sed, I've never found it. You could always try piping it into Perl:
Code:
cat file | perl -ne 'print unless /^(NPD|NA2)/;'
Google The UNIX and Linux Forums
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 04:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66