Solved

How can I remove a record from a large Unix file ?

Posted on 2011-03-25
6
789 Views
Last Modified: 2012-05-11
I have a Unix file that has a bad record in it that needs removed.

The file is too large for vi, it says "No space left on device".

So how can I remove the bad record ? it has "MB6     0" in position 86 for 9.

Through other testing, I also know what record # it is.
0
Comment
Question by:Alaska Cowboy
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 75 total points
ID: 35215827
If you have enough space to store the big file twice:

    sed NNd bigfile > bigfile.copy

where NN is the record number (e.g. "sed 2d bigfile > bigfile2" to remove line 2).
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35215845
This assumes that the "record" is a text line.  If this is a file sith some other format (fixed-length fields, binary values and so on) then "sed" won't work.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35215847
This assumes that the "record" is a text line.  If this is a file sith some other format (fixed-length fields, binary values and so on) then "sed" won't work.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 50 total points
ID: 35215884
awk  '{if(substr($0,86,9)!="MB6     0") print}' largefile > largefile.tmp
mv largefile.tmp largefile

wmp
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 35216001
simon and woolmilkporc, thanks ! I will try both options.
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 35216126
ok, both worked ! thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now