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.

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).

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.

grep solution

grep -v '^NA2\|^NPD' file > new_file

file type:

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

grep is not doing anything.
new_file is still with the same records.
anything with the sed?

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:

cat file | perl -ne 'print unless /^(NPD|NA2)/;'

Work's for me :cool:

$ cat file
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
$ grep -v '^NA2\|^NPD' file > new_file
$ cat new_file
NMT000010000100001ENVL,CSP,28#,9X12,KFT,1C                                                        00001
TOP63120
NP2                                                                                                                                                                                                                                                                                                                                                               
00000000000000 00000000000000                                                             000                                                                                    
00000000000000                               00000000000001 00000000000000                                               00000000000000
NMT000010000800001PAD,LGL RL,PRISM,LTR,BE
$ wc -l file
       8 file
$ wc -l new_file
       6 new_file

Or sed

$ sed '/^NA2/d;/^NPD/d;' file > new_file2
$ wc -l new_file2
       6 new_file2

:b:well both are doing good.
but in perl just wanted to move the records and not print them...
anyways some research from my side is good for me also ....:b:

Dan, dont know why the 'grep -v' not working but your 'sed' option is working [